So, as mentioned in the previous post, this entry will be about Animations and things required for them.
Now, some of you reading might already know that I used to work for a Game Studio already in the past. I left due to personal reasons, and I'm already happy to see that 3 of my games have already been published after I left. Puts a sense of pride in me knowing that something of mine is already out in the market. (Don't know how well they're selling, but they were my first commercial games!)
Now, when designing the animation procedures I remembered that animations weren't super easy to calculate. But I have the extra complication of having to do the calculations for 3D space and not 2D spaces. But, I've created a 2 simple animation functions and I'll be able to now expand easily on them.
Of course, since I'm working on new work in the GameLibrary I'm doing all the testing in my 3D match-3 game since it's technically the tech demo. (Plus, I needed these here urgently or I couldn't do anything else!)
- The first animation I completed was a GoToScale function. This is what it sounds like. It takes a scale, either X,Y,Z scales, or a complete Vector and a time frame and will scale the object up/down accordingly in the specified time. I also added an optional callback so that you can know when your animation is done. (This is something I've programmed from my past work I designed before and I still love this system so why rewrite what works right?)
- The second animation... GoToPosition! The backbone of any video game. How do you make things move automatically without having to recode the movement everytime... with GoToPosition! Just like GoToScale it takes X,Y,Z or a Vector and an optional callback!
Well now, with these two animations complete and running I had to update the 3D cube a little. New click functions call the GoToScale now, and if the two pieces are next to each other, they slide into the other's place smoothly. Next chunk of code to be added is the comparison so see if a match has been made!
Now, I'm going to make some developer's lives a little easier, and some of you pro's out there might wince and think I'm an idiot but here we go!
My basic multistage animation system technique!
First, background info about how I developed my technique:
At the previous studio I was at, I had to do a lot of animations for my games. Everything from an animated score scroller to flipping sprites. Well, I had originally had done everything with a sequential set of functions. But this caused really bloated code with loads and loads of single use functions. I spent about 30 minutes and came up with this 1 function technique that I still love and use.
First, make a function... give it a good name cause you only have to call it once!
Now. Here's my favorite part. You can do this two ways:
First, a parameter in the function that's just a number or....
A global variable specifically for this animation.
Either way works, just depends on what your callback system can handle. Currently, my system can't handle me sending the next "step" through the callback so I'm going to be doing it with a specific Global variable. (Yes, not efficient, but I wanted to get the animations working quickly)
Alright. Next Step... a Switch!
Each step runs the specific animation aspect for this step and then breaks out and does nothing.
function. But, here's the trick, if you're doing multiple items setup the longest animation of this step to have the callback back to this exact same function. Break out of the switch and then increment the counter.
Now, here's the joy... each previous animation step will callback the function and each stage will run in order and you don't have to dig through hundreds of lines of code to find each stage of the animation.
Here's a rough example of the technique:
public void AnimationExample()
{
switch (GlobalStep)
{
case 1:
GoToPosition(NewPosition, Time, AnimationExample);
break;
case 2:
GoToScale(NewScale, Time, AnimationExample);
break;
default:
FinalizeAnimationCode();
}
GlobalStep++;
}
That's it! I've used this technique hundreds of times in my games. I created an entire Story board system using this technique. It works great and I love how simple it is to edit so that you can expand and shrink the animations to your hearts content.
Well, that's it for this edition of the Diary. We'll see what's happened the next time I update... Hang around for the next installment.
No comments:
Post a Comment