views:

108

answers:

0

I have three actions that are triggered in the CCSequence. The way I want it to be fired is that first the sprite should move in the center of the screen and then the scale action is fired. But for some reason the sprite moves to the center of the screen correctly but when the scale is fired it uses the old sprite position.

id actionRotate = [CCRotateBy actionWithDuration:0.6 angle:360]; 
        id disappear = [CCFadeTo actionWithDuration:.5 opacity:0]; 
        id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(removeAlphabetToFindFromView:)];
        id actionScale = [CCScaleBy actionWithDuration:0.6 scaleX:10 scaleY:10]; 
        id moveTo = [CCMoveTo actionWithDuration:0.6 position:ccp(windowSize.width/2, windowSize.height/2)]; 


        //[self removeAlphabetToFindFromView2:alphabetToFind]; 

        [alphabetToFind runAction:[CCSequence actions:moveTo,actionScale,disappear,actionMoveDone, nil]];

UPDATE 1:

Maybe the startAnimation method has something to do with this. I have public x and y variables which is used as x and y positions for 4 different sprites:

-(void) startAnimation:(CCSprite *) sprite
{

    [self generateRandomCoordinates]; 

    id actionMove = [CCMoveTo actionWithDuration:3.0 position:ccp(x,y)];
    id actionRotate = [CCRotateBy actionWithDuration:0.0 angle:rotateBy]; 

    id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(finishedMoving:)]; 

    [sprite runAction:[CCSequence actions:actionMove,actionRotate, actionMoveDone, nil]];

}

-(void) finishedMoving:(id) sender
{

    if(counter == randomAlphabets.count) 
    {
        counter = 0; 
    }

    CCSprite *sprite = [randomAlphabets objectAtIndex:counter]; 

    [self generateRandomCoordinates]; 

    [self startAnimation:sprite]; 

    counter +=1; 

}

UPDATE 2:

As expected the x and y used in the startAnimation method (getRandomCoordinates) were causing the problem. So, I removed all the actions before firing the sequence and now it works fine.