Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL Animation when using large sprite sheets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 rootoutcast   Members   -  Reputation: 101

Like
0Likes
Like

Posted 05 December 2012 - 08:03 PM

Hi everyone I am new to gamedev.net, I am working on a super mario style game. I have used sites such as lazyfoo.net and sdltutorials.com. to get information. The problem I am trying to solve is that I have a sprite image each frame for the sprite is 64x64 pixels the sheet is set up in 5 columns the rows are for each animation state such as standing, walking and jumping all have a different number of frames depending on what the animation is.

From Looking at lazyfoo's site his animation tutorial looks like you have to set the position of each frame individually. My image has 64 frames of animation. I am looking for another way of cliping the sprites.

Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 17234

Like
0Likes
Like

Posted 05 December 2012 - 08:26 PM

You could calculate the clip rects using math, and wrap it in a function.
rect.x = (column * SpriteWidth)
rect.y = (row * SpriteHeight);
rect.w = SpriteWidth;
rect.h = SpriteHeight;

Several years ago, I created a single header file that wraps it all for you providing convenience functions.
[SDL_tileset]

That thread's formatting has deteriorated with time, but the download link still works. If you have any questions, just ask.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

[Fly with me on Twitter] [Google+] [My broken website]

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#3 eppo   Crossbones+   -  Reputation: 2312

Like
0Likes
Like

Posted 06 December 2012 - 07:43 AM

If you're on D3D10+ hardware, you might want to use texture arrays (as long as all sprites are the same size) as they prevent filtering artifacts between neighboring sprites.
Instead of cutting sprites out of a sheet in a shader you can do it at load-time.

Edited by eppo, 06 December 2012 - 08:03 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS