Ahem…i know this tutorial is availabel on almost all tutorial websites but everyone starts with something simple…..so in this tutorial i will tell you how to make a moving character and add friction and other effects..
Movement is found in most flash games like RPG’s and many more.
So first start with drawing a circle.Then convert it to a Movie Clip and then open the actions panel and wirte the following actions-
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
}
Now the explationation:
This part:
onClipEvent (load) {
speed = 5;
}
Means that when the move is loaded it sets a variable called speed and it’s value is equal to 5.
The next Part
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
}
In this part it checks that if the Left key is pressed the value of x coordonates decerease by the value of speed(which is 5).
You can simple understand what it means just the same as above with the corresponding keys.
In the next part you will learn how to make character which rotates and diagonal movement and collision detection with walls….
Filed under: Uncategorized | Tagged: Actionscript, flash, flash tutorials, movement tutorial