Pages: 1
Topic closed
I know, it's a silly question - but I always have to copy a project's jumping sprite and use it in my game. How do I make a simple sprite jump and fall back down on black colored terrain?
If you could tell me I'd really appreciate it
Offline
Ok first you need a variable called yVelocity. Now, put int the following code.
<when green flag clicked>
<set{ yVelocity }to( 0
<forever>
<if> <touching[ ground or ground colour
<set{ yVelocity }to( 1
<if> <key[ up Arrow ]pressed?>
<set{ yVelocity }to( 15
<end>
<end>
<change{ yVelocity }by( -1
<change y by( <{ yVelocity }>
<end>
Last edited by archmage (2008-01-28 14:58:05)
Offline
It depends
Simple way:
When you press the jump key,
glide to position (x) + 20, (y) + 20
glide to position (x) +20, (y) -20
So your sprite will jump diagonally up and forwards, 20 pixels and fall diagonally back down.
Of course, if your background is moving, you don't need to add anything to (x).
***
You can get much more complicated if you start having gravity, and you will probably want to do that if your project requires jumping on platforms rather than just jumping over obstacles.
For that, you will need a gravity script that causes your sprite to fall when not standing on a platform, and a jumping script that causes the sprite to move upwards and ignore the gravity until it reaches the top of its arc.
See Gobo and The Flood, or my "Complex Jumping Demo"
***
Or you can start getting into realistic jumping where you have vertical velocity that gets modified by gravity... but one step at a time, hmm?
Offline
Topic closed
Pages: 1