Apr 10, 2007

Move with the arrow keys...

Example: Ball movement

First creat a circle, let's say 50 x50 ( instance name = ball) This tutorial will be very basic, so here it is....
After you creat a movie clip add this to the first frame of the document : ( I'll explain through)

onEnterFrame = function () {

\\this code loops over when it is over this frame...

if (Key.isDown(37)) {
ball._x= ball._x-2;
}
\\Key Number (37) means left arrow key and it says if you press it the x position will move left or \\will substract its position by 2 so it moves the objects position. "Ball" is just telling flash what is going to be moved.
if (Key.isDown(38)) {
ball._y= ball._y-2;
}
\\Key Number (38) means up
if (Key.isDown(39)) {
ball._x= ball._x+2;
}
\\Key Number (39) means right
if (Key.isDown(40)) {
ball._y= ball._y+2;
}
\\Key Number (40) means down
}

You close your script and it is done, you can move your Clip with your arrow keys, if yuo want to set it faster just change the 2 in every key command, this two sets the pizels the object will move when you press the arrow button..
And Remember that its more recommendable to set frames per second to 25, for a smoother animation....
Hope you find it Usefull


Ivan

No comments:

FlashGrounds

FlashGrounds
Kevin Stubbs, Ivan Alvarez Malo