Would you know how to change the value of flashPosX ? A “log” in changeFlashPosX works fine, but the value does not change:
-(void)changeFlashPosX{
CCLOG(@"change");
flashPosX = random() % 300;
CCLOG(@"rando : %f", flashPosX);
}
-(void)animFlash{
CCScaleTo *to1 = [CCScaleTo actionWithDuration:.2 scale:1];
CCScaleTo *to0 = [CCScaleTo actionWithDuration:.6 scale:0];
CCMoveTo *moveTo = [CCMoveTo actionWithDuration:0.1 position:ccp(flashPosX, flash.position.y)];
CCCallFunc *callChange = [CCCallFunc actionWithTarget:self selector:@selector(changeFlashPosX)];
CCSequence *seq = [CCSequence actions:to1, to0, callChange, moveTo, nil];
//CCAction *repeatSeq = [CCRepeatForever actionWithAction:seq];
CCRepeatForever *repeatSeq = [CCRepeatForever actionWithAction:seq];
[flash runAction:repeatSeq];
}
The output :
rando : 164.000000
change
rando : 217.000000
change
rando : 241.000000
change
rando : 75.000000
Try this:
If it works, then the issue is either with the scope and/or retention of your
flashPosXvariable, or with the routine loop called by theCCSequence.Also, try this: