在我的安卓游戏中,我正在尝试生成一个飞过屏幕的弹丸,并使用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);
}
任何帮助都将不胜感激。