In my game I have a gif that walk back and forth with a speed of 1, and when it hits a wall the gif changes it speed to -1. How can I make my gif flip it self when it changes speed to -1 and stay that way until it changes it speed again.


1 2 3 4 5 | if ((speed == - 1 && getX() < 10 ) || (speed == 1 && getX() > getWorld().getWidth()- 10 )) { getImage().mirrorHorizontally(); speed = -speed; } |
1 2 3 4 5 | if ((speed == - 1 && getX() < 10 ) || (speed == 1 && getX() > getWorld().getWidth()- 10 )) { getImage().mirrorHorizontally(); speed = -speed; } |
1 | if (speed < 0 ) getImage().mirrorHorizontally(); |
1 | if (speed < 0 ) getImage().mirrorHorizontally(); |
1 2 3 4 | public void mirrorImagesHorizontally() { for ( int i= 0 , i<images.length; i++) images[i].mirrorHorizontally(); } |
1 2 3 4 5 | if ((speed == - 1 && getX() < 10 ) || (speed == 1 && getX() > getWorld().getWidth()- 10 )) { speed = -speed; mirrorImagesHorizontally(); } |
1 2 3 4 | public void mirrorImagesHorizontally() { for ( int i= 0 , i<images.length; i++) images[i].mirrorHorizontally(); } |
1 2 3 4 5 | if ((speed == - 1 && getX() < 10 ) || (speed == 1 && getX() > getWorld().getWidth()- 10 )) { speed = -speed; mirrorImagesHorizontally(); } |