This project has moved. For the latest updates, please go here.

Beginner Question - Animated Frames and geometries

Topics: User Forum
Feb 21, 2010 at 5:54 AM


I've been a software engineer for a few years but am completely new to game programming. I'm finding it very different from my day job but extremely enjoyable!  I discovered your engine and think it could solve a lot of headaches that I'm having with my first game.

I'm looking for a best practice when using animated frames that may have different bounding rectangles.  For instance, the flying animations are 16x24 while the running animations are 16x16, etc.  What is the best way to attach bodies/geometries here?  Should I create a single body/rectangle for the player and somehow update the size of the collision geometry rectangle as I go from running to flying?  Or do I need multiple bodies/geometries for each set of animations?  Any insight here would be much appreciated!

Feb 25, 2010 at 2:00 PM


Not sure how much this will help but it talks about good practice when completely changing direction and bodies. I personally have not done anything like this yet.

Feb 26, 2010 at 3:24 PM
Edited Feb 26, 2010 at 3:25 PM

The best way to do it in my opinion, is to keep a geometry and body for each "shape" of your animation. Store two dictionaries, one for your bodies and one for your geometries with the key as the associated animation name. Then you can use that to retrieve the appropriate geometry when you switch animations. At this point you can just retrieve the current  geometry and put all other geometries into a stasis or remove them from the physics simulator. (though I would just set them to ignore to avoid the cost of readding and removing them over and over again)

public class Character
	public string CurrentAnimationName { get; set; }
	public Dictionary<string, Body> Bodies { get; set; }
	public Dictionary<string, Geom> Geoms { get; set; }

	public Body PrimaryBody
		get { return this.Bodies[this.CurrentAnimationName]; }

	public Geom PrimaryGeometry
		get { return this.Geoms[this.CurrentAnimationName]; }

	public void ChangeAnimation (string newAnimationName)
		this.CurrentAnimationName = newAnimationName;
		// Put all other bodies and geoms into "stasis" here