Hi there!
I'm working in a 2D OpenGL project and I'm wondering if it's better to use various images for an animation or use a single imageSet containing all the sprites and then drawing a sub-image each time...
So for example let's say I have 3 kinds of characters with 4 sprites each one (and each sprite is 64 x 64). Which is the better option (for OpenGL performance)?
Option1:
Code:
// Three arrays of four images each one:
for(int i=0; i<4; i++)
{
spritesChar1[i] = [[Image alloc] initWithImage:[...]];
spritesChar2[i] = [[Image alloc] initWithImage:[...]];
spritesChar3[i] = [[Image alloc] initWithImage:[...]];
}
// So I have 12 (64 x 64) images allocated, but each time I have to render one I do it for the entire image:
(...)
[spritesChar1[sprite] renderAtPoint:p];
Option2:
Code:
// Three images containing each one the four sprites:
spritesChar1 = [[Image alloc] initWithImage:[...]];
spritesChar2 = [[Image alloc] initWithImage:[...]];
spritesChar3 = [[Image alloc] initWithImage:[...]];
// So I have 3 (256 x 64) images allocated, but each time I have to render one I have to get a sub-image to draw only the sprite:
(...)
[spritesChar1 renderSubImageAtPoint:p WithOffset:offset AndSpriteSize:size];
Option3:
Code:
// A single image containing the three characters and each character's sprites:
spritesChars = [[Image alloc] initWithImage:[...]];
// So I have 3 (256 x 196) images allocated, but each time I have to render one I have to get a sub-image to draw only the sprite:
(...)
[spritesChar1 renderSubImageAtPoint:p WithOffset:offset AndSpriteSize:size];
Which is the best way for performance?
Thanks for your time!