Hi everyone,
I'm searching for some hours now, reading every thread here, but still finding no solution for my Problem. So I hope you guys can help me killing this bug. :)
I've a character with many different Animations. He walks, he jumps, he idles and so on...
For every animation I got a png file with the Sprite-Atlas and a .plist file with the coordinates of the single images.
Now I wrote a function which generates, for each Sprite-Atlas, a new Manager, a new Sprite and a new SpriteAnimation and stores them in a dictionary, which is the return value of this function.
The function is located in my Singelton Manager Class, so I can call it from all my other Classes to generate a new Animation. So the character, the enemies, the world are calling this function.
The returned dictionary will be added to a Dictionary-Property in these objects and the manager will be added as a child to the layer.
Now everytime I need a specific animation I make the Sprite visible and start its Animation.
Three Animations worked fine in one class but the fourth one kills the app. It starts to stutter very hardly. CPU Usage seems to be 100% but only on the devices, NOT in the simulator.
What can be the problem?
Do I realy need a new Manager for every .png Sprite-Atlas?
Thank you very much,
here is an example call:
[self.animationDict addEntriesFromDictionary:[[Manager defaultManager] generateNewAnimaton:@"walk" capacity:32 image:@"walk.png" delay:0.04f width:71 height:64 seq:@"walk.plist"]];
[self addChild:[animationDict valueForKey:@"walkManager"] z:1];
here's the function:
- (NSMutableDictionary*) generateNewAnimaton: (NSString*)name capacity:(int)capacity image:(NSString*)image delay:(float)delay width:(int)width height:(int)height seq:(NSString*)sequence
{
animationDict = [NSMutableDictionary dictionary];
AtlasSpriteManager* manager = [AtlasSpriteManager spriteManagerWithFile:image capacity:capacity];
AtlasAnimation* animation = [AtlasAnimation animationWithName:name delay:delay];
NSDictionary* d = [NSDictionary dictionaryWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:sequence]];
NSArray* kList = [[d allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for( NSString* key in kList )
{
NSDictionary* myDict = [d objectForKey:key];
NSInteger x = [[myDict valueForKey:@"x"] integerValue];
NSInteger y = [[myDict valueForKey:@"y"] integerValue];
NSInteger w = [[myDict valueForKey:@"w"] integerValue];
NSInteger h = [[myDict valueForKey:@"h"] integerValue];
[animation addFrameWithRect: CGRectMake( x, y, w, h ) ];
}
AtlasSprite* sprite;
sprite = [AtlasSprite spriteWithRect:CGRectMake( 1, 1, width, height ) spriteManager: manager];
sprite.visible = false;
sprite.transformAnchor = CGPointMake( 0, 0 );
[manager addChild:sprite];
[animationDict setValue:manager forKey:[name stringByAppendingString:@"Manager"]];
[animationDict setValue:animation forKey:[name stringByAppendingString:@"Animation"]];
[animationDict setValue:sprite forKey:[name stringByAppendingString:@"Sprite"]];
return animationDict;
}