Hi, guys,
I am using AtlasSprite, AtlasSpriteManager and AtlasAnimation to make animation.
What I find out is that it costs me nearly 1 M memory per Class.
The sprite sheet I used for each class is 512 X 256 or sometimes 256X256. It's only 80 KB each.
Is it normal? It costs nearly 1M memory per sprite sheet!
Is there any Trick I can apply to reduce Memory usage in the Game?
Right now my memory usage is 32 MB, not good!
below is the codes I use to generate animation,
Thanks
by the way, I am using 0.72
[Texture2D saveTexParameters];
[Texture2D setAliasTexParameters];
mgr = [AtlasSpriteManager spriteManagerWithFile: movingSpriteSheetImageName capacity:50];
[self addChild:mgr z:0];//tag:kTagSpriteManager];
[Texture2D restoreTexParameters];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString* plistPath = [[NSBundle mainBundle] pathForResource:spriteSheetPList ofType:@""];
NSDictionary* content = [NSDictionary dictionaryWithContentsOfFile:plistPath];
content = [content objectForKey:@"frames"];
NSDictionary *plistDictionary = [content objectForKey:@"moving"];
NSArray* keysArray = [plistDictionary allKeys];
if( [keysArray count] > 0)
{
AtlasAnimation *animation = [AtlasAnimation animationWithName:@"moving" delay: movingAnimationRatio];
keysArray = [keysArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for (id key in keysArray) {
NSDictionary *tmp = [plistDictionary objectForKey:key];
int x = [[tmp objectForKey:@"x"] intValue];
int y = [[tmp objectForKey:@"y"] intValue];
int w = [[tmp objectForKey:@"width"] intValue];
int h = [[tmp objectForKey:@"height"] intValue];
if (spriteImage == nil){
spriteImage = [AtlasSprite spriteWithRect:CGRectMake(x, y, w, h) spriteManager: mgr];
[mgr addChild:spriteImage];
}
[animation addFrameWithRect: CGRectMake(x, y, w, h) ];
// [tmp release];
}
movingAction = [[RepeatForever actionWithAction: [Animate actionWithAnimation: animation ] ] retain];
[spriteImage addAnimation: animation];
}