SimplyKiwi
SimplyKiwi

Reputation: 12444

Animating CCSprite not working?

I am creating a sprite like this in my init method (mySprite is declared in the .h):

mySprite = [CCSprite spriteWithFile:@"Image1.png"];
        [mySprite setPosition:ccp(100, 300)];
        [self addChild:mySprite z:1 tag:1];

Then in my other method, I try to animate it like so but it doesn't seem to animate at all, I also know that the method that this is in is getting called because I NSLogged it. Anyway here is how I try to animate mySprite:

CCSequence *moveSequence = [CCSequence actions:[CCMoveTo actionWithDuration:5 position:ccp(120, 400)],[CCMoveTo actionWithDuration:4 position:ccp(100, 300)], nil];
    [mySprite runAction:[CCRepeatForever actionWithAction:moveSequence]];

Any ideas why this might be happening?

Thanks!

Upvotes: 0

Views: 325

Answers (1)

Loic Argelies
Loic Argelies

Reputation: 561

At first glance this part of the code seems right, so perhaps you would need to show more of your overall program so that we can examine what happens between your init function and your other method being called.

A couple things out of the blue:

  • make sure to call retain on your sprite so that it does not get removed summarily until you are done with it
  • what is "self" exactly here, is it a cocos layer? Is the layer added to the scene properly (ie, are you seeing the sprite being displayed, even if it does not move)?
  • I would also look to see if anything in the scene graph might happen between the "init" call and that second method of yours, in which you execute the animation code. Is there a StopAllActions somewhere? A removeFromParent or removeAllChildren, perhaps?

Cheers

Upvotes: 1

Related Questions