Organize sprites in tiles or individual files?

Advanced game related topics
PHP
User
User
Posts: 79
Joined: Sat Sep 10, 2005 5:38 pm

Organize sprites in tiles or individual files?

Post by PHP »

Hello,

What is the best way to organize the respective movement direction sprites for your characters?

Copy them all into a so-called “tile” for each character and then copy them out using ClipSprite() and use them?
(you can see an example of this in the middle)

Image

Or put all the graphic files for a character in a separate folder and handle them differently?

Are there any limitations regarding the maximum sprite size with the first tile method?

Thanks for all your tips!
ricardo_sdl
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Sep 21, 2019 4:24 pm

Re: Organize sprites in tiles or individual files?

Post by ricardo_sdl »

I think the main advantage of having all your sprites in a single image file is the reduced memory usage.
You can check my games at:
https://ricardo-sdl.itch.io/
PHP
User
User
Posts: 79
Joined: Sat Sep 10, 2005 5:38 pm

Re: Organize sprites in tiles or individual files?

Post by PHP »

But isn't it basically easier to use tiles?

Let's say I have 5 characters, each with 8 movement types.

Tiles:
Load 5 sprites and use ClipSprite() to copy the current movement from the sprite.

Files / individual sprites:
Load and process 5 * 8 = 40 files / sprites.
User avatar
minimy
Addict
Addict
Posts: 894
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Organize sprites in tiles or individual files?

Post by minimy »

Hello PHP and Ricardo. Personally I prefer to do it this way:

1) Create a structure or map for the sprites.
Here you can store id, group, health...
2) Load the PNG image.
3) Use a procedure to create and draw the frame want on the sprite. And thus get all the sprites.
In the procedure you can pass the group to which it belongs, if you have several groups of sprites.

It may be more work at the begin, but later is easy to store your sprites. With 5 sprites it may not be noticeable, but if you have 400 sprites it shows in the speed, you save 'cutting' each sprite in each cycle, and if there are 400 there are a lot of cuts.

But as they say in my country, 'Every teacher has his little book'.
It is best to use the way that is most comfortable for you and also depends on the type of game, number of sprites, etc.
If translation=Error: reply="Sorry, Im Spanish": Endif
ricardo_sdl
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Sep 21, 2019 4:24 pm

Re: Organize sprites in tiles or individual files?

Post by ricardo_sdl »

In my small game I'm doing like this:
Image

Each sprite or sprite sheet has its own file. All of them are loaded at the game start. I don't have many of them so memory usage shouldn't be a problem.

It's easy to use, if I need to change some sprite I only touch a single file. I think that the approach of having all your sprites (for different objects, enemies, icons, tiles etc) in a single file is called sprite atlas, and there is software that can help you generate the sprite atlas and other files to allow you load the correct sprites on your code, here is one:

https://witnessmonolith.itch.io/atlased
You can check my games at:
https://ricardo-sdl.itch.io/
Carm3D
Enthusiast
Enthusiast
Posts: 196
Joined: Mon Feb 17, 2025 10:04 am

Re: Organize sprites in tiles or individual files?

Post by Carm3D »

I put them on sheets, but they are all mostly related for creating animated elements.
https://imgur.com/kBLa8QF
miso
Enthusiast
Enthusiast
Posts: 712
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Organize sprites in tiles or individual files?

Post by miso »

In the scope that is assumed by the reference image, I would say do what fits best to your coding style. You won't have problems using either methods.

For a more generic answer: I use sprite atlas if sprite is animated and the environent is OpenGL or Ogre3d with orthographic camera, and I use individual sprites if environment is pb 2d screen.

For short reasons for that last one: my sprites are often not big but small ones. There were a technical switch in pb 2d once, currently these are textured quads. There are now two sprite sizes: quadsize and texturesize. When you load a sprite, the quadsize will be the same as the texture size. If you zoomsprite to get a scale, you modify the quadsize. If you clipsprite, you modify the uv of the texture within the texturesize. If you want a new frame, you have to reset clipping ( to get the original sizes ) but that will also reset zoomdata. You clip again, you zoom again instead of reuving.

I'm sure it's for backward compatibility, but for me it's so confusing, that I only use clipsprite for some effects like changing pages of a book.
miso
Enthusiast
Enthusiast
Posts: 712
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Organize sprites in tiles or individual files?

Post by miso »

PHP wrote: Wed Feb 04, 2026 5:08 pm Are there any limitations regarding the maximum sprite size with the first tile method?
Thanks for all your tips!
I missed that one, yes there is. It is the maximum texture size and depends on the video card. It's safe to use a 2048x2048 sprite atlas, but you can go one tier up higher if necessary.
PHP
User
User
Posts: 79
Joined: Sat Sep 10, 2005 5:38 pm

Re: Organize sprites in tiles or individual files?

Post by PHP »

By the way, I always talked about ClipSprite(), which is nonsense, of course. I meant GrabSprite(), which always fetches the corresponding figure from the “atlas” for me...

Edit: Oh, I see that GrabSprite() isn't right either, because it doesn't copy part of a sprite, but the entire screen.
PHP
User
User
Posts: 79
Joined: Sat Sep 10, 2005 5:38 pm

Re: Organize sprites in tiles or individual files?

Post by PHP »

Image

The AI is hallucinating again, but actually that's exactly the command I need ;)

Or were the target parameters actually available in PB at one point and have since been removed?
Post Reply