Chloe's Harder to Follow but still more better than Neuro's Custom Animation Engine
Author: | Chloe Sagal
|
Submitted: | 4th October, 2012
|
Views: | 9773
| Rated: |
|
|
WARNING: This article isn't as user friendly as mine usually are
Alright, this isn't so much of a tutorial as it is me blurting out the nonsense inside of my brain. If you can't follow along, my bad, but hopefully if you're smart enough, you can grasp the concept. I don't have much time, so if someone wants to create an .mfa of this, be my guest. It's either that or I share the entire source code for the game I'm working on, which I don't think I'll be doing. :/
First of all, grab yourself an animated object or character, you're going to need to throw some values down. In the alterable values add these values:
Animation Frame
Animation Cool
Animation Speed (optional, can slow down your animations)
Animation Repeat (sets the frame that the animation repeats to)
FrameSkip (optional, speeds up slower animations)
ID
In the alterable strings, add these:
Animation
Play Animation
Animation Direction (optional, can be used to play animations backwards)
Add a new qualifier to this object, this will be designated for every object that uses animation.
Add every frame you have for that character into the stopped animation, none of the other properties should matter, though you might try turing the loop on or off if things stop working.
Add an ini object to your frame.
NOTE: usually I'll have a level properties active, just to hold values for the level, and I'll add a folder location (I.E. data\) and an animation file (I.E. animations.txt) then at the start of the frame load AppDrive$+AppDir$+dataFolder+animationFile so I can change them at any point in time, it saves for headaches later if I want to change any file names.
Go to the destination of the ini file, and create the file with the name you designated.
In the file, create a group that looks like this:
[Default]
Speed =
Start =
End =
Repeat =
R.Frame =
ToAnim =
Direction = Forward
FrameSkip = 1
Take note, if you didn't create the speed, direction and frameskip values, don't worry about adding them here.
The line in the brackets is the group name, and can be used as the name of your animation for instance, [Running]
Speed is how many 'ticks' until the next frame plays, for instance, 0 will play the games frame rate, 1 will be every other tick, and so on.
Start is the first frame of your animation (the exact frame as it is in the stopped animation)
End is the last frame of the animation
Repeat is how many times the animation will repeat, I usually set it up so 0 plays through one, 1 repeats once and so on, and -1 is for infinite.
R.Frame is the frame that the animation will repeat to, for instance if you have a slight intro on one of your animations, yeah yeah yeah, just like the default engine.
ToAnim is a string to help you out if you don't want any extra code for animations you know turn into something else. It is simply the name of another animation that you want to play as soon as this animation finishes.
Direction I set to either forward or reverse, tells the code which way the animation should go.
Frame skip is how many frames the animation will skip. This is simply just a timesaver, in case one of my animations has so many frames it moves way to slow and it doesn't look bad enough to simply rework it. You can expiriement with values in this and the speed value to get the speed you really want. Setting it to zero will freeze the animation, so set it to 1 for default.
For a final example, here's one of my completed entries:
[Walking]
Speed = 0
Start = 181
End = 240
Repeat = -1
R.Frame = 181
ToAnim = False
Direction = Forward
FrameSkip = 1
Once you have your animations set up, we can start working on some code.
1. Start by always spreading a value in the ID value for the first line of code.
2. On the second line of code, you'll determine if there are any animated objects and start a loop for how ever many there are:
Number of Animated object qualifier > 0
:Start loop Object Selection Animation Number of Animated object qualifier times.
The most important thing to remember is since MMF2 has a terrible time with object selection, this loop handles that. Basically it checks every single animated object, handles them, then finishes the tick. To throw a line of code into that process, simply start the conditions with On Loop Object Selection Animation and If ID of Animated object qualifier is equal to Loop Index of Object Selection Animation. From here on out, I won't be writing that out.
3. Next is just a safety precaution, this code will check to see if the object has no animation, and st it to whatever you consider your default animation.
On loop
ID of Object = Loop Index
Animation =
:Set Play Animation to Idle
4. Next we are going to create a line of code to handle changing animations. Rather than throwing a whole bunch of these all over the place, I find it's easier to just have it all in one spot, hense the need for the Play Animation string. Basically, when a string is thrown into that alt string, it will locate that group name in the ini file, set all the values to the object, then change the animation name to that string and erase whatever is in the play animation value.
On loop
ID of Object = Loop Index
Play animation <>
:Set animation frame to GroupitemValue(INI,Animation Name(Object),Start)
:Set animation speed to GroupitemValue(INI,Animation Name(Object),Speed)
:Set animation Repeat to GroupitemValue(INI,Animation Name(Object),Repeat)
:Set FramSkip to GroupitemValue(INI,Animation Name(Object),FrameSkip)
:Set animation Direction to GroupitemString$(INI,Animation Name(Object),Direction)
:Set Animation to Play Animation
:Set Play Animation to
5. This next line of code forces the animated object to use the code we've been hammering out
On Loop
ID of Object = Loop Index
:Force animation frame to Animation Frame value
6. Now we get to use that Animation cool value, which basically tells the animation when to move to the next frame.
On Loop
ID of Object = Loop Index
Animation Cool > 0
:Subtract 1 from animation Cool
7. This line of code will handle moving the animation frames forward .
On Loop
ID of Object = Loop Index
Animation Cool = 0
Animation Direction = Forward
:Add Frameskip to Animation Frame
:Set Animation Cool to Animation Speed
8. This is the same thing as line 7, though it handles playing in reverse
On Loop
ID of Object = Loop Index
Animation Cool = 0
Animation Direction = Reverse
:Subtract Frameskip from Animation Frame
:Set Animation Cool to Animation Speed
Finally these last lines of code will handle what happens to the animation once it has finished, whether it be repeating or going to a new animation.
9. This is for playing forward, and repeating infintely.
On Loop
ID of Object = Loop Index
Animation Frame > GroupitemValue(INI, Animation, End)
Animation Direction = Forward
Animation Repeat = -1
:Set Animation Frame to GroupitemValue(INI, Animation, R.Frame)
10. This is for playing forward, and repeating a certain amount of times.
On Loop
ID of Object = Loop Index
Animation Frame > GroupitemValue(INI, Animation, End)
Animation Direction = Forward
Animation Repeat > 0
:Set Animation Frame to GroupitemValue(INI, Animation, R.Frame)
:Subtract 1 from Animation Repeat
11. This is for finishing an animation that is playing forward.
On Loop
ID of Object = Loop Index
Animation Frame > GroupitemValue(INI, Animation, End)
Animation Direction = Forward
Animation Repeat = 0
:Set Play Animation to GroupitemValue(INI, Animation, ToAnim)
The last three lines of code are exactly the same as lines 9,10 and 11, except the conditions:
Animation Frame > GroupitemValue(INI, Animation, End)
And
Animation Direction = Forward
Change to:
Animation Frame < GroupitemValue(INI, Animation, End)
Animation Direction = Reverse
Now, if you want another animated object, so long as they share the same alterable strings/values, all you have to do is add that same qualifier.
If you want to create a new animation, simply open that INI file and add it.
And if you want to change an animation, simply throw the name of the animation into the "Play Animation" string.
So that's that, sorry I bottomed out at the end there. If I need to go over anything let me know.
|
|
Chloe Sagalunder the influence of FUN Registered 19/02/2009
Points 607
|