@5:/\/\@1|\|!!!!!!!11111
__________
This tutorial will teach you the basics to a game like Dad 'n Me...the movement style.
Before you do anything,make a new movieclip.Make 2 frames.In the first frame,add a picture of your character standing.In the second frame,add a movieclip of your character running/walking.Also,add stop(); actions to each frame.Now keep reading.
Please don't be stupid.Add the code to the character MC :)
Start off by adding the variables.
onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}
We'll need to separate speed settings,one for the _x movement and one for the _y movement.The speeds need to be different,to give the game a somewhat realism effect thingy.Also,we'll use _xscale to change which way the character faces on each key press.
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed2;
this.gotoAndStop(2);
}
'if':Here is the first ClipEvent.Using te 'if' function,we can create a Key.isDown function,so you can make the effects.When there is an 'if',there is a 'then'.Now,the first part of the script will be Key.UP.This doesn't really have to be UP,but it is right now.
'then':Now,your then will be movement and making your character walk.If you remember,the movieclip has 2 frames,standing and walking.You will be directed to frame 2 in the movie test when you press the buttons.Also,_y -= speed2; will make your character move upwards,and as you see,with him still facing one direction:left or right.The next parts of the script are exactly the same,just changed for different directions.
if (Key.isDown(Key.DOWN)) {
this._y += speed2;
this.gotoAndStop(2);
}
Same,just moves your character down with a 'plus'(+) sign.
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
You notice 2 things in this part of the script._y has changed to _x,and a new 'then' code has been added,the _xscale code so your character will turn.Please make sure your character starts off facing the right way :)
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop(2);
_xscale = +scale;
}
}
Same as above,just the 'minus'(-) sign has been changed to a 'plus'.
Now,to end this script,we need to use a new script to change the frame back to frame 1 and stop the walk/run animation.
onClipEvent (keyUp) {
this.gotoAndStop(1);
}
Notice how 'enterFrame' changed to 'keyUp'?Yah.
Here is the full code...
onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed2;
this.gotoAndStop(2);
}
if (Key.isDown(Key.DOWN)) {
this._y += speed2;
this.gotoAndStop(2);
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop(2);
_xscale = +scale;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
}
Change the speed to whatever to make the speeds faster or whatever.Also,if you want to make the movement work with the keys 'W','S','A',and 'D',then just use the keycode example below...
65=A=LEFT
68=D=RIGHT
83=S=DOWN
87=W=UP
Do not make the code Key.65 or whatever,just use the number...example.
onClipEvent (enterFrame) {
if (Key.isDown(65)) {
this.gotoAndStop(4);
}
}
The end :)