|
This can be used for making all sorts of games. This will make a character walk left/right when the appropriate arriw keys are pressed.
First, draw your character facing left, convert that to a movieclip.
Go into the movieclip (double click it) and in the second frame, create a new movieclip, and inside of it, draw your character walking to the right. Now, go back to the first movieclip you made and go to the third frame, draw your character facing left. In the fourth frame, make a new movieclip of your character walking to the left.
Now, exit all the movieclips. Now, apply this actionscript to the main movieclip: (press F9 to open actionscript panel)
| CODE | onClipEvent (load) { moveSpeed = 5; } onClipEvent (enterFrame) { if (Key.isDown(Key.RIGHT)) { _root.keydown = "right" this._x += moveSpeed; this.gotoAndStop(2); } else { if (_root.keydown == "right") { this.gotoAndStop(1); } } if (Key.isDown(Key.LEFT)) { _root.keydown = "left" this._x -= moveSpeed; this.gotoAndStop(4); } else { if (_root.keydown == "left") { this.gotoAndStop(3); } } } onClipEvent (load) { if (Key.isDown(Key.RIGHT))(false); { this.gotoAndStop(1); } } |
Feel free to edit it all you want, and enjoy.
--------------------
|