-
Creating a Loop
I am new to java and I am recreating Super Mario Bros for the NES in Greenfoot. I am early on in my project but I need some help making Mario's legs move :(
Here is the code I have currently:
Code:
public void checkKeys()
{
if (Greenfoot.isKeyDown("left") )
{
if(onGround() )
setImage(marioRL);
moveLeft();
}
if (Greenfoot.isKeyDown("right") )
{
if(onGround() )
setImage(marioRR);
moveRight();
}
if (Greenfoot.isKeyDown("x"))
{
if(onGround() )
{
if(getImage() == marioRR)
{
jump();
setImage(marioJR);
}
else
{
jump();
setImage(marioJL);
}
}
}
}
I need my mario images to loop with the normal mario stance, and right or left running stance. So when the keys are pressed this loops until the key is released, or he is not onGround().
Thanks in advance.
-
When I did a simple little game, I used a thread that ran the animation process, first it would update the gamestate, for example if the up key is pressed change the state of the object/s accordingly, and then paint the new state on screen. I'd reccomend you take a look at Killer Game Programming in Java, I don't remember which specific chapter it was, but it does explain the concept behind a side scroller, including animating the character and paralax scrolling, also, my threaded animation idea came from there.
-
-
It sounds hard, good luck!