AS: Combo:
AS: Main – Teh one to rule 'em all?
Knowledge needed:
Basic actionscript knowledge: gotoAndPlays, if statements, onClipEvents, and preferably _currentframe function (Which will be explained anyways).
Introduction:
Today you are going to be programming a complete simple combo system. Some parts of the code may depend on your animations; you are going to use _currentframe.
The code I am going to post allows to create a total of 4 animations in the combo. However, you will be able to add / delete some of the combos (You can have 100 combos if you want :))
This is not a complicated tutorial, everything you need to know is how to use onClipEvents, if statements, and simple Actionscript actions such as gotoAndPlay();.
You will also be needing a good knowledge of how frames work, including frame instances and simple "stop();" and "play();" functions.
Especially if you are new to Actionscript - For your own good, DO NOT copy and paste the code without reading the entire thread once or twice.
Feel free to modify the code to your likes, I just don't advise you to use this code if you don't understand how it works, then it means you don't actually learn anything... Anyways, do as you wish, I hope you aren't getting bored - we're getting started!
The "_currentframe" funtion:
What is it?
This function basically allows you to detect on what frame an object is(Teh object's timeline).
It is extremely easy to use yet a very useful function that can save you quite a lot of time.
It is mainly used for attacks in games, for example:
if(_currentframe == 1 && Key.isDown(Key.SPACE)){// && Means "and".
this.gotoAndPlay("Attack frame");/*"Attack frame" is a frame labled "Attack frame" with an animation of some guy attacking.*/
}
What is it used for?
Simple: to find out what frame an object is currently playing.
Example:
if(_currentframe == x){
//action
}
Frame instances
To add an instance (name) to a frame, simply click the frame once and go to the propeties window. Then, type whatever you want in the textbox that should appear.
Then you can freely use gotoAndPlays or gotoAndStops using the name of the frame.
Example:
if(_currentframe == 3 && Key.isDown(Key.SPACE)){
this.gotoAndPlay("<Put teh name here>");
}
When/ How/ Where is it used?
It is used a lot for Game Overs, simple character animations, etc...
I think it can only be used with gotoAndPlays or gotoAndStops.
Okay, this is getting boring, let's go on!
The combo engine. (Finally).
The code may depend on your animations, it can totally contain 4 como animations, but you can modify it to your likes. If you have any questions about how to modify it, feel free to ask.
1. You need to have four animations in four different movie clips, all set in different frames.
2. When you've put all the 4 animations into the MovieClip, make sure every animation has the amount of frames that it actually contains. (See picture below).
3. Name the first frame of every animation "combo1","combo2", etc...
4. Finally add this code:
onClipEvent(mouseDown){
if(this._currentframe == 1){ // if the frame number is "one".
this.gotoAndPlay("combo1");//Plays animation number 1.
}
if(this._currentframe > 20 && this._currentframe < 29){/* change those numbers to the frames from where the player can begin the 2nd animation to the last frame of it.*/
this.gotoAndPlay("combo2");// Plays animation number 2.
}
if(this._currentframe > 33 && this._currentframe < 43){/* change those numbers to the frames from where the player can begin the 3rd animation to the last frame of it.*/
this.gotoAndPlay("combo3");// Plays animation number 3.
}
if(this._currentframe > 45 && this._currentframe < 54){/* change those numbers to the frames from where the player can begin the 4th animation to the last frame of it.*/
this.gotoAndPlay("combo4");// Plays animation number 4.
}
}
I hopr I have been clear enough, don't hesitate to e-mail me if you're having any problems.
Good luck :)
