I’m working on XNA C# when I came upon this problem where I need to store easily editable animation data such that my game will be able to render and play it.
It’s something like this:
I have a texture flying across the screen from (0,0) to (800,600) pixels. This will last 5s.
How do I represent it in data and also write it such that the game is able to interpret and do the necessary in the Draw and Update methods. It’s OK if I need to do some extensive coding.
A simple domain specific language could help; create an AnimationDirector class that would interpret the statements from the animation script and do the appropriate work during
DrawandUpdate. The DSL itself could be as simple aswhich will create an object with texture
textureat (0,0) and move it to (800,600) over a 5 second period, and then destroy it.If you want something a little more useful,
which will let you get more creative, and expand the possibilities of animation (such as adding rotation, etc. if you desire such).
Now, when you need to run an animation, just pass the appropriate resource name to the director, and let it handle things from there. Alternatively, you could create some kind of AnimatedEntity which refers to a particular script, and calls the AnimationDirector itself for
DrawandUpdate; depending on how you’ve done your engine so far, this might be more fitting to its design.