0

在我的 android 游戏中,我试图生成一个飞过屏幕并使用 4 个 .png 文件制作动画的弹丸。但是,每当产生弹丸时,它都会使整个应用程序崩溃。这是我的代码:

protected void addProjectile() {
    CCSprite projectile = CCSprite.sprite("projectile1.png");
    CCAnimation projectileAnimation = CCAnimation.animation("", 0.1f);
    for (int i = 1; i <= 4; i++) {
  projectileAnimation.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("projectile" + i + ".png"));
    }
    CCAction projectileAction = CCAnimate.action(1, projectileAnimation, true);
        projectile.setPosition(CGPoint.ccp(winSize.width + (projectile.getContentSize().width / 2.0f), winSize.height / 2));
        addChild(projectile);
        projectile.setTag(1);
        _projectiles.add(projectile);

        int minDuration = 3;
        int maxDuration = 6;
        int rangeDuration = maxDuration - minDuration;
        int actualDuration = rand.nextInt(rangeDuration) + minDuration;

        CCMoveTo actionMove = CCMoveTo.action(actualDuration, CGPoint.ccp(-projectile.getContentSize().width / 2.0f + 320, winSize.height / 2));
        CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "spriteMoveFinished");
        CCSequence actions = CCSequence.actions(actionMove, actionMoveDone);
        projectile.runAction(actions);
        projectile.runAction(projectileAction);
}

任何帮助,将不胜感激。

4

0 回答 0