Still day one learning Cocos. Love it btw.
I've been playing with the Hello World, Hello Actions and Hello Events examples. Then I saw the "SpecialActions" like Waves. When I apply the Wave effect to my "grossini.png" sprite, the "Hello World" label disappears. I am trying to figure out how the two are connected. I don't want the Waves animation to force my label to vanish if I can.
Code Snipit:
Init function:
// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
self.isTouchEnabled = YES;
self.isAccelerometerEnabled = YES;
// create and initialize a Label
Label* label = [Label labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// ask director the the window size
CGSize size = [[Director sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];
id action = [ScaleBy actionWithDuration:3.0f scale:2.5f];
[label runAction:action];
Sprite *sprite = [Sprite spriteWithFile:@"grossini.png"];
sprite.position = ccp( 0, 50 );
[self addChild:sprite z:1 tag:kTagSprite];
id rotateAction = [RotateBy actionWithDuration:4 angle:180*4];
id jumpAction = [JumpBy actionWithDuration:4 position:ccp(size.width,0) height:100 jumps:4];
id forward = [Spawn actions:rotateAction, jumpAction, nil];
id backwards = [forward reverse];
id sequence = [Sequence actions: forward, backwards, nil ];
id repeat = [Repeat actionWithAction: sequence times:2];
[sprite runAction:repeat];
}
return self;
}
Touch End handler:
-(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//return kEventIgnored;
UITouch *touch = [touches anyObject];
if(touch)
{
CGPoint location = [touch locationInView: [touch view]];
CGPoint convertedPoint = [[Director sharedDirector] convertCoordinate:location];
CocosNode *sprite = [self getChildByTag:kTagSprite];
[sprite stopAllActions];
id waves = [Waves actionWithWaves:1 amplitude:30 horizontal:YES vertical:NO grid:ccg(5,2) duration:1];
// -- If I comment this one line out, the "Hello World" label doesn't disapear.
[sprite runAction: [RepeatForever actionWithAction: waves]];
//if( sprite.rotation != 0 )
// [sprite runAction:[Spawn actions:waves, [RotateTo actionWithDuration:1 angle:(rand() % 360)], [MoveTo actionWithDuration:1 position:convertedPoint], nil]];
//else
// [sprite runAction:[MoveTo actionWithDuration:1 position:convertedPoint], nil];
return kEventHandled;
}
return kEventIgnored;
}