Hi there!
I'm working in a 2D OpenGL project and now I'm building the image system. For example, let's say I have an object that must be animated in a 4 sprites loop. It's better to have it's 4 images individually or to have a single image that contains the 4 images?
Here it goes the code assuming the 4 individual images way:
Code:
// Loading 4 images (32 width x 32 height each) in an image array...
img[0] = [[Image alloc] initWithImage:(...)@"sprite1.png"];
img[1] = [[Image alloc] initWithImage:(...)@"sprite2.png"];
img[2] = [[Image alloc] initWithImage:(...)@"sprite3.png"];
img[3] = [[Image alloc] initWithImage:(...)@"sprite4.png"];
(...)
//And to show them:
[img[frame] renderAtPoint:(...)];ç
frame++;
if(frame > 3)
{
frame = 0;
}
And if I use the one imageSet method...
Code:
// Load a single 64 width x 64 height image
imageSet = [[Image alloc] initWithImage:(...)@"imageSet.png"];
(...)
// And to show them:
switch(frame)
{
case 0:
[imageSet renderSubImageAtPointStartingAt:(0,0) Dimensions:(32,32) (...)];
break;
case 1:
[imageSet renderSubImageAtPointStartingAt:(32,0) Dimensions:(32,32) (...)];
break;
case 2:
[imageSet renderSubImageAtPointStartingAt:(0,32) Dimensions:(32,32) (...)];
break;
case 3:
[imageSet renderSubImageAtPointStartingAt:(32,32) Dimensions:(32,32) (...)];
break;
}
frame++;
if(frame > 3)
{
frame = 0;
}
Which way is preferred to optimize memory, and which way makes game go faster? Let's say I have like 10 different types of image with 4 to 6 frames each, which means to load around 50 individual images, or to load just 10 images but with higher dimensions...
Thanks in advance!