Hey guys! I new at cocos2d world, i by now i tryng do a little animation, but i really dont get the point of AtlasSpriteManager, i gonna make some questions and after i post my code ok?
1 - AtlasSpriteManger is like a Sprite right? so whenever is been added you only can move, change whatever in the same place right? I cannot make one class to manage all my AtlasSprite and add this whatever i want, this always gonna stay where my AtlasSpriteManager is been added is right?
2 - I have one AtlasSprite with 2 simple animations i have found in net, just to test, in the first 3 i have one walk man, and the bottom 3 i have the jump animation, so i do this to make then move:
//whatever.m
id walkAnimation;
id jumpAnimation;
//whatever.h
-(id) init
{
self = [super init];
if (self != nil)
{
mgr = [AtlasSpriteManager spriteManagerWithFile:@"-2.png" capacity:6];
[self addChild:mgr];
buneco = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 77, 129) spriteManager:mgr];
[buneco setPosition:ccp(130,100)];
AtlasAnimation *aaWalk = [AtlasAnimation animationWithName:@"walk" delay:0.1f];
for(int i=0;i<3;i++)
{
int x= i % 3;
[aaWalk addFrameWithRect: CGRectMake(x*77, 0, 77, 129) ];
}
id aWalk = [Animate actionWithAnimation: aaWalk];
walkAnimation = [RepeatForever actionWithAction:aWalk];
AtlasAnimation *aaJump = [AtlasAnimation animationWithName:@"jump" delay:0.5f];
for(int i=0;i<3;i++)
{
int x= i % 3;
[aaJump addFrameWithRect: CGRectMake(x*77, 129, 77, 129) ];
}
jumpAnimation = [Animate actionWithAnimation: aaJump];
[buneco runAction:walkAnimation];
[mgr addChild:buneco];
[mgr.texture setAliasTexParameters];
jump = NO;
isTouchEnabled = YES;
[self schedule:@selector(doStep:)];
}
return self;
}
The man walk perfectly
And at the TouchesBegan i want he do the jump move:
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
if (!jump)
{
jump = YES;
[buneco stopAction:walkAnimation];
[buneco runAction:jumpAnimation];
}
}
The problem is the jumpanimation seens not exist! But if i set the first animation to the jumpanimation he do it well.
This is some scope problem? I Doing something wrong? Or i really very very dumg i dont get the point for AtlasSprite!