Jump to content
  • Advertisement
Sign in to follow this  
Sabo

Programming a 2D spritesheet animation system

This topic is 2001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am about to start working on a 2D animation system using spritesheets. Below are my plans for this system, but before I implement it I thought I would ask for some thoughts and opinions.

 

  • Not all frames in all animations are of the same size. I then map each frame to a rectangle with the size of the frame which will save me a few bytes of memory.
  • I plan to have an array of frame times to allow different frame time for each frame. Will make it easier to control the animation.

Good? Bad?

 

I am also curious about how to best implement some kind of achor point. A simple example, a guy is standing straight (thin and high frame), then falling over (wide and low frame). Using either of the corners as an anchor point, the "standard/default" way, would result in the guy not only falling over, but also moving sideways on the screen. To solve this the anchor point needs to be set to the feet. Right? If so, I will also need an array for the anchor point for each frame, where the anchor point will indicate how much to move the sprite up/down and left/right. Or?

 

Am I missing something? Better way of doing things?

Share this post


Link to post
Share on other sites
Advertisement
Guest Hiwas

While not completely what you may be looking for, you might take a look at http://esotericsoftware.com/ at least as an example.  While it is a multi-piece system instead of single image animations, the basic concepts are likely going to be very similar at the base level.  Given the provided open source runtimes, it may save you time to take a look.

Share this post


Link to post
Share on other sites

While not completely what you may be looking for, you might take a look at http://esotericsoftware.com/ at least as an example.  While it is a multi-piece system instead of single image animations, the basic concepts are likely going to be very similar at the base level.  Given the provided open source runtimes, it may save you time to take a look.

Hmm... I had not planned to use skeletal animation for this particular game. Either way, big thanks for the link. I will definitely have a closer look at their stuff since chances are I will use skeletal animation in a coming project. Might even change my mind for the current project.

Share this post


Link to post
Share on other sites

You've pretty much covered what I have in my sprite code. My reference point is beneath the center of gravity of the figure, where the ground would be if the unit were standing. This is also marks the vertical displacement of the unit in the position vector. If I could go back, I think I would just make the reference point the center of gravity of the unit.

 

Actually, if I could go back in time, I would do a skeletal system.

 

Edit: no, really, if I could go back, I would use a 3rd party tool...

Edited by jms bc

Share this post


Link to post
Share on other sites

I'd allow for points and boxes to added to each frame as metadata.  In addition to allowing a "center of gravity" element, it would enable the following features to be added trivially:

 

1) collision boxes (often not the same as the sprite boundaries)

2) vulnerability / attack boxes (the intersection of a player's vuln. box and an enemy's attack box would trigger damage, for example)

3) spawn points for bullets

4) sound triggers (lets you play sfx for attacks, footsteps, etc., at precise timings)

 

I've used systems like this in the past, and they can be surprisingly powerful.  You could write a fairly simple tool in a day or two to let you graphically edit and place boxes and points in your sprite frames.

 

The variable-sized frames sound good, but I'd stick with fixed-size until you're sure that the memory savings is worth the complexity.

 

The time-per-frame is a good feature.  90% of the time, you'll want your frames to be evenly spaced, but i could see it coming in handy for some specific cases.

 

have fun!

 

Share this post


Link to post
Share on other sites

Alright. Thanks for the input. Good information in all posts. Will give it some more thought before I go ahead. Much appreciated.

Share this post


Link to post
Share on other sites

I am about to start working on a 2D animation system using spritesheets. Below are my plans for this system, but before I implement it I thought I would ask for some thoughts and opinions.

 

  • Not all frames in all animations are of the same size. I then map each frame to a rectangle with the size of the frame which will save me a few bytes of memory.
  • I plan to have an array of frame times to allow different frame time for each frame. Will make it easier to control the animation.

Good? Bad?

 

I am also curious about how to best implement some kind of achor point. A simple example, a guy is standing straight (thin and high frame), then falling over (wide and low frame). Using either of the corners as an anchor point, the "standard/default" way, would result in the guy not only falling over, but also moving sideways on the screen. To solve this the anchor point needs to be set to the feet. Right? If so, I will also need an array for the anchor point for each frame, where the anchor point will indicate how much to move the sprite up/down and left/right. Or?

 

Am I missing something? Better way of doing things?

 

I'm a noob but I guess I could tell you how I did this.

 

I used a Animation class to handle the animation itself. Then it had a list of Frameset class instances and a pointer to the current Frameset which it used to loop over it.

The Frameset class had a list of Frames and ability to add Frames etc. The Frame class had x/y cords for the image and offsets and some more stuff.

 

I hope you get the idea, some time ago since I coded it.

 

Maybe someone with actual skill can tell you how much my version sucks. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!