Hello
I'm recreating the Mario Bros game. I would like to animate my Mario character by alternating two images when I press the right key and two other images when I press the left key. But I can't animate it. That is to say that when I press the right key, there is only an image displayed. When I press the left key, there is only one image displayed.
Thanks in advance to anyone who finds my error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | private void checkPress() { if (Greenfoot.isKeyDown( "right" )) { setImage(image1); setLocation(getX() + speed, getY()); checkObstacle(); animationRight(); } if (Greenfoot.isKeyDown( "left" )) { setImage(image2); setLocation(getX() - speed, getY()); checkObstacle(); animationLeft(); } if (Greenfoot.isKeyDown( "up" )) { jump(); } } public void animationRight() { if (getImage() == image1) { setImage(image3); } else { setImage(image1); } } public void animationLeft() { if (getImage() == image2) { setImage(image4); } else { setImage(image2); } } |