Sign in to follow this  

Managing spritesheets

This topic is 1113 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

So, I am doing this DX9 wrapper in a game programming course and I am thinking of the best way of handling spritesheets for animation and such. I havent had any previous experience of game libraries in C++, but in Java. So I would appriciate any thoughts on best practise on this.

Should i keep a list of RECT's of each individual sprite in the sheet, or should i create a new RECT from col/row calculations everytime I draw a sprite? That is if even using LPD3DXSPRITE in this way is the only/best method?

Share this post


Link to post
Share on other sites

Either approach is fine, though the first is potentially faster. It's only a must if you have non-uniform rectangles.

 

Since this is a course, stick with ID3DXSprite, it will make your life much easier - unless it's a course requirement to actually implement a self-rolled sprite batcher (management of vertex declaration, vertex and index buffers, draw calls etc.). If you're new to DirectX you're really better off using the convenience D3DX library first wink.png

Share this post


Link to post
Share on other sites

I'm agreeing with unbird - also I'd say it depends on how much animation data you end up with. Originally for animated characters, I used even rows for each animation (walk row, run row, jump row, etc... ) but I added tons and tons of animations and started hogging the video ram with numerous 4086x4086 sheets. I found a compressed atlas worked better. The only tricky part then is getting the program to recognize which rectangle sections belong to which animation. If you put each animation frame from your sheet on a separate layer in your image editor and use an export layers to files option (however you do it in your editor) - ie: layers: walk1, walk2, walk3, etc... then use a utility like: Sprite Sheet Packer or something similar which will export a space-saving sprite-sheet as well as a .txt file containing all the rectangles. You can parse the .txt file and use the corresponding names and numbers to automatically match up the animation frames to their place on the sheet and save a lot of video ram (and manual work).  

That being said, however, either approach is good for your purposes I think. Only would be necessary to do it that way if video-ram becomes a concern.

Share this post


Link to post
Share on other sites

Difference being on how the spritesheet is put together - like if I made the animation cycle so that each frame is spaced equally apart so the animation module can simply change the source rectangle each frame by some even amount -- then I will use a bit more space on the sheet than if all the source rects were packed tightly together(in which case I couldn't use the same technique and would therefore need precise locations for all the animation frames). I guess this wouldn't be an issue if all your animation frames were close to the same size, however if your character is doing really crazy things in each frame it may be easier to use a sprite sheet packer to assemble the sheet and rectangle definitions for you.

  For more compression (data compression) you could use a DXT type compression in video memory. I know in XNA it is just a matter of changing the properties of the texture in the content pipeline but I'm not sure how it is done otherwise. DXT is lossy so is good for background stuff but I don't know if I recommend it for characters that you will see in front of you all the time if a crisp vibrant image is important to you.

Good luck on your project :)

Edited by renman29

Share this post


Link to post
Share on other sites

Ok, thank you for your explaination. That could be usefull in the future, but when i have only a few sheets its a bit overkill, especially since i am using a tool to create the character sprites and they are all put in a sheet already, so i would have to split them up and then fuse them back together.

Share this post


Link to post
Share on other sites

This topic is 1113 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this