0

I have an object going across the screen with an animation using the following code:

    CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFrames("ninjastar.plist");
    CCSpriteSheet projectileSheet = CCSpriteSheet.spriteSheet("ninjastar.png");
    addChild(projectileSheet);
    ArrayList<CCSpriteFrame> projectileSprites = new ArrayList<CCSpriteFrame>();

    for (int i = 1; i <= 4; i++) {
        projectileSprites.add(CCSpriteFrameCache.spriteFrameByName("ninjastar" + i + ".png"));
    }

    CCAnimation projectileAnimation = CCAnimation.animation("throw", 0.1f, projectileSprites);
    CCSprite projectile = CCSprite.sprite(projectileSprites.get(0));
    CCAction projectileAction = CCRepeatForever.action(CCAnimate.action(projectileAnimation, false));
    projectile.setPosition(CGPoint.ccp(winSize.width + (projectile.getContentSize().width / 2.0f), actualY));
        actionMove = CCMoveTo.action(actualDuration, CGPoint.ccp(-projectile.getContentSize().width / 2.0f + 320, actualY));
projectileSheet.addChild(projectile);
    projectile.setTag(1);
    _projectiles.add(projectile);
    CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "spriteMoveFinished");
    CCSequence actions = CCSequence.actions(actionMove, actionMoveDone);
    projectile.runAction(actions);
    projectile.runAction(projectileAction);

I'm using "spriteMoveFinished" to remove the sprite once it is done going across the screen:

public void spriteMoveFinished(Object sender) {
    CCSprite sprite = (CCSprite)sender;
    _projectiles.remove(sprite);
    sprite.stopAllActions();
    removeChild(sprite, true);
}

However, when the sprite gets to the end of the screen it just stays stuck there on the last frame. How do I remove it completely?

Akarsh M
  • 1,629
  • 2
  • 24
  • 47
Frozsht
  • 305
  • 1
  • 3
  • 8
  • did you verify that spriteMoveFinished was indeed called ? – giorashc May 12 '13 at 06:26
  • Yes, because if I take out "sprite.stopAllActions();" in spriteMoveFinished the sprite gets stuck at the side of the screen still animating continuously. But when I add "sprite.stopAllActions();" it gets stuck at the side of the screen on the last frame of the animation instead. – Frozsht May 12 '13 at 07:09

0 Answers0