Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL Animation when using large sprite sheets

Started by rootoutcast Dec 6, 2012 at 2:03 AM 1 replies 2.5k views
Original Post
rootoutcast
rootoutcast
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.
Servant of the Lord
Servant of the Lord
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.

eppo
eppo
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.