Search tutorials
function checkForKeys(){
if(Key.isDown(Key.LEFT)){
if(char.xSpeed<0){
char.xSpeed = 0
}
char.xSpeed += .5
char._xscale = -100
} else if(Key.isDown(Key.RIGHT)){
if(char.xSpeed>0){
char.xSpeed = 0
}
char.xSpeed -= .5
char._xscale = 100
} else {
char.xSpeed = 0
}
if(Key.isDown(Key.UP) && char.jump!=true && char.falling==false){
char.ySpeed = 12.5
char.jump = true
}
if(char.jump==true){
char.ySpeed -= .5
}
if(char.ySpeed<=-12.5){
char.ySpeed = 0
char.jump = false
}
char._y -= char.ySpeed
world._x += char.xSpeed
}
This is pretty long, but its something thats easy to remember, if you think about all the variables. First, we change the characters xSpeed if the left or right keys are pressed. The characters _xscale property changes to add more of a feel to it. Note that in the character movie clip, his x position is -25. This is because otherwise, his position would change when the left key was pressed. If his xSpeed is in the other direction, it is set equal to zero, so you can go in the other direction quicker. If neither key is down, the characters position stays the same. Then, if the up key is pressed, and the character isnt jumping and isnt falling.(well use these variables later) His ySpeed variable is set to 12.5(normally this wouldnt be so high but we want our character to go really high so people will be amazed) Also, the jump variable is set to true, so he cant jump again. We will use this variable later. Then, if jump is set to true, the characters ySpeed will gradually go down, then we make it so that when its the opposite of what it started as, it goes back to 0, and jump is set to false. Finally, we make the character move according to its variables. Note that in this game, the world moves according to the characters xSpeed. In some games, this wont happen. On the next page, well check for collisions. This will include the falling variable we used earlier. Take note because collision checking in these games is much more complicated than in my other tutorial
| » Level Intermediate |
|
Added: 2004-12-29 Rating: 6 Votes: 14 |
| » Author |
| I love making flash games but it's really annoying when Flash doesn't work! |
| » Download |
| Download the files used in this tutorial. |
| Download (17 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!