Hi there!
I've wrote part of my app successfully using normal Sprites and Animation. But since it includes more and more image files I thought it would be a good idea to rewrite some parts of that app so that it would use AltasSprite.
I used ImageMagick to merge images of the same "control" but different states into a singe image (one file per one control). And started rewriting the parts that used Sprite class to AtlasSprite and AtlasSpriteManager.
I have two problems though:
1. A huge one. Since it would be complicated to operate on main core of the app - I've started testing Atlas* classes on my splash screen scene which just displayed logo and was replaced by the main scene after a second. The thing is - when I use Atlas* classes it doesn't even display it. Here's my code:
@implementation SplashScene
- (id) init {
self = [super init];
if (self != nil) {
//Sprite * bg = [Sprite spriteWithFile:@"splash.png"];
//bg.position = ccp(240, 160);
//[self addChild:bg z:0];
mgr = [AtlasSpriteManager spriteManagerWithFile: @"splash.png"];
sprite = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 200, 200) spriteManager:mgr];
sprite.position = ccp(10, 10);
[self addChild: sprite z: 1];
}
return self;
}
@end
The commented code with Sprite works, the second one doesn't. Even when I set position to AtlasSpriteManager and add it as a child instead of AtlasSprite itself. All I see is a blank screen. SplashScene is a subclass of the Scene class.
2. Originally when I used Sprite classes I used Animation to change "states" of those sprites.
Sprite * spr = [Sprite spriteWithFile: @"somefile.png"];
sprite.position = ccp(10, 10);
Animation * anim = [[Animation alloc] initWithName:@"states" delay:0];
for(int i = 0; i < 3; i++)
{
Texture2D * t = [[TextureMgr sharedTextureMgr] addImage:[self loadImage: "somefile" withStateNumber:[NSString stringWithFormat:@"%d", i]]];
[anim addFrameWithTexture:t];
}
[sprite addAnimation: anim];
[anim release];
So I made sprite with the default state of the control, than added rest of the states as an Animation for that sprite. And when I wanted to set change the state i just used
[sprite setDisplayFrame: @"states" index: STATE_NUMBER];
But since now every state is in one file instead of separate file for every state - it's impossible to do it that way. Is there some other way to make Animation or is it made some way different with AtlasSprite and it doesn't use Animation for it?