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.
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);
}
}
