Hello,
So I am trying to create the beginnings of a 2D platforming game. I have images for my Stickman character set and I have even gotten a working idle animation and movement acceleration. However, now I want to try and make it so that my character faces the direction of movement.
I have tried looking this up online, but all of the solutions I have seen deal with games where the movement can happen in all four directions from a top-down view. However, in a platformer game that I'm trying to make, the movement is only left and right with the exception of jumping. This means I would have to use the mirrorHorizontally() function, but I am having trouble making it so that the character stays the direction they're facing when they are moving left and right.
Here is my code for flipping the image. My variable isLeft is set to true because I created the default images with my character facing left. If I did not give enough information about my problem I would be glad to help further.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | private boolean isLeft = true ; if (Greenfoot.isKeyDown( "left" ) == true ) /** logic to flip image going left */ { if (isLeft == false ) { this .getImage().mirrorHorizontally(); } isLeft = true ; } if (Greenfoot.isKeyDown( "right" ) == true ) /** logic to flip image going right*/ { if (isLeft == true ) { this .getImage().mirrorHorizontally(); } isLeft = false ; } |