Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Strip images  (Read 3390 times)

0 Members and 2 Guests are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Strip images
« on: October 19, 2008, 10:04:58 pm »
Hi

How much different would be using one image with much "sub-images", where sprites draws from selecting subrects, instead of using separated images for all these "subimages"?

I did few simple 2D games before (in other APIs and languages), where I had most of the sprites with fixed size (ex: 32x32), so a strip image was fine. This time I have animations which frames have different sizes.

I have to decide if I save separated images with just the needed rectangle on each, or save all in one as a strip image, which may have a lot of junk pixels (because of compensations from different sizes).

I also can try to minimize the junk pixels cropping and joining images by hand or by a dynamic algorithm, (and having a table indicating the coordinates for each one) but I hope to avoid it.
Pluma - Plug-in Management Framework

Kreeg

  • Full Member
  • ***
  • Posts: 115
    • View Profile
Strip images
« Reply #1 on: October 19, 2008, 10:40:39 pm »
This technique is called clipping and you can use it with SFML. Check out the member of sf::Sprite !
Attention (va) aux (sur) messages (mon) subliminaux, (blog) camarade !

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Strip images
« Reply #2 on: October 20, 2008, 04:26:09 pm »
Hm.. What do you mean? What member?

Imagine a fall down animation witch have 2 frames:
Code: [Select]

\o/              
 |    and  =-|o


- I can save the 2 frames horizontally aligned in a unique image, and there will be junk pixels because second pic height is smaller than the first one.
Then a sprite will use setSubRect to have first or second frame (according to the size of each frame, stored somewhere)
Its one image like this:
Code: [Select]

_________
|\o/=-|o|  
| | ####| <--  junk pixels in bottom right
---------


- Alternatively, frames are saved as separated images, without junk pixels, and the sprite will use setImage to have first or second frame.
It's two Images like this:
Code: [Select]

_____        ______
|\o/|   and  |=-|o|
| | |        ------
-----




Thinking that I could have much animations, each one with much frames of different sizes, how different could be the 2 alternatives? Shouldn't I care about the extra memory used to store unused pixels in strip-images? How much better (or not) would be using a big image instead of 50 small ones (for instance)
Pluma - Plug-in Management Framework

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Strip images
« Reply #3 on: October 20, 2008, 07:42:21 pm »
You can do either and they will have extremely similar performances I'm sure, but using multiple images will likely save you only a couple bytes per frame.
Likewise, using a single image will reduce the amount of time it takes needed to load frames by some milliseconds, but increase the time it takes for switching frames by about a hundredth of a nanosecond.
It's up to your personal preference really, since they don't have any major advantages over the other; I use sprite sheets (or strip images) for my game engine because it's a lot easier to edit a single image than multiple.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Strip images
« Reply #4 on: October 20, 2008, 08:10:32 pm »
Thank you very much!
I'll probably use separated images then.
I'm doing a sprite editor before start with the game engine itself. In that editor, a sprite sheet is loaded and then saved after a little process. So I did this question to decide the best format to save them.

With separated images the size and coordinates table isn't needed also.
So, for each sprite, I receive the sprite sheet, split it into multiple small images and save them all in a data file. This file will be loaded into memory by the game engine, and a vector of images are loaded from that allocated memory.

Edit: interesting, looking at setImage of sf::Sprite code I see that mySubRect isn't adjusted when an image was set before, I always have to call both setImage and setSubRect. Not big issue, but..
Pluma - Plug-in Management Framework

 

anything