Results 1 to 4 of 4
Thread: Creating a Loop
- 04-01-2010, 05:55 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
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:
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().Java 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); } } } }
Thanks in advance.Last edited by SenorJalapeno; 04-01-2010 at 06:02 AM.
- 04-01-2010, 04:02 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
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.
- 04-01-2010, 08:03 PM #3
Cross Posted
Java Programming - Creating a Loop
Any more?
db
- 04-02-2010, 10:13 AM #4
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Creating files stopped creating...
By Dieter in forum Advanced JavaReplies: 3Last Post: 09-25-2009, 11:45 PM -
Creating Checkerboard from a 2 dimensional 'for' loop.
By New2Java in forum New To JavaReplies: 3Last Post: 07-23-2009, 07:45 AM -
Creating Checkerboard from a 2 dimensional 'for' loop
By New2Java in forum New To JavaReplies: 1Last Post: 07-22-2009, 10:10 PM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 08:46 PM -
Creating a New Method for Square Root Loop
By SapphireSpark in forum New To JavaReplies: 14Last Post: 02-25-2009, 01:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks