First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
Search tutorials
Author: Jesse
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 it’s something that’s easy to remember, if you think about all the variables. First, we change the character’s xSpeed if the left or right keys are pressed. The character’s _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 character’s position stays the same. Then, if the up key is pressed, and the character isn’t jumping and isn’t falling.(we’ll use these variables later) His ySpeed variable is set to 12.5(normally this wouldn’t 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 can’t jump again. We will use this variable later. Then, if jump is set to true, the character’s ySpeed will gradually go down, then we make it so that when it’s 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 it’s variables. Note that in this game, the world moves according to the character’s xSpeed. In some games, this won’t happen. On the next page, we’ll 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
(10 being the highest)
» Author
I love making flash games but it's really annoying when Flash doesn't work!
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

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

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.