尝试使用cocos2d动画精灵时Android应用程序崩溃

时间:2013-05-08 05:00:09

标签: android animation cocos2d-iphone sprite cocos2d-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);
}

任何帮助都将不胜感激。

0 个答案:

没有答案