Sprite Animation and Farseer

May 29, 2010 at 5:48 PM
Edited May 29, 2010 at 5:49 PM

Hello again, I have seen this topic has already emerged in the forums but I didn't saw anyone giving some solid information about it (there were a few good ideas that I tried out).

The thing is that I want to have a character with sprite animations in a platformer like these:

There is the idea of creating different geoms. And now here comes my first question, different geom (and body?) for each action (sprite sheet), for example one geom (and body) for "Run" and one for "Jump", or different geom (+ body) for each frame (that I assume would be cruel for the engine)?

In this sollution I don't get how to make sure that every geometry (lets say you have 3 for idle,run, jump) moves along correctly with the others (especially if you have geoms with signifficant difference is size, for example Run, Crouch)?

Then I had the idea of creating and disposing a body/geom each time the action changing (run -> jump ->idle -> jum p etc) in order to have only one body/geom at all times. This was working at some point but still there a lot of things to take into consideration. First of all it make no sense for the engine, but I think there is also the danger of creating a geom in a place where you shouldn't (for example when you are next to a wall and make an action with wider geom than the previous one, a part of the new geom may end up inside the wall).

Finally is the idea of not using Farseer since I want a character with Sprite Animation. I understand that this may be the better solution but I want to make sure that there are no other working alternatives before dropping Farseer.

Is there anyone out there that has achieved something like this or have any insights about what I wrote? Thanks in advance for your time.


May 29, 2010 at 8:53 PM

One solution in FPE 2.x is to pre-create all the geometries needed to represent every state the character can have. When your character changes state, you simply deactivate the previous state (geometry) and activate the new one. Creating geometries is where the penalty lies - the distance grid algorithm used in the narrow phase uses a lot of CPU time and memory. It makes sense to only create each geometry once and then reuse it.