当我删除通过CCAnimation动画的精灵并触摸它时,我想减少(一)该值,但我发现的结果是多于一个值减少。这个显示得分:
public void showLabel(int scr)
{
if(scoreLabel != null){
this.removeChild(scoreLabel,true);
}
CGSize winSize = CCDirector.sharedDirector().displaySize();
scoreLabel = CCLabel.makeLabel("Score : " + scr, "Verdana", 20);
scoreLabel.setColor(ccColor3B.ccBLACK);
scoreLabel.setPosition(55f, winSize.height - 15);
addChild(scoreLabel);
这个处理精灵检测和交叉:
ArrayList<CCSprite> targetuToDelete = new ArrayList<CCSprite>();
for(CCSprite targetd : _targetd)
{
CGRect targetRect11 = CGRect.make(targetd.getPosition().x - (targetd.getContentSize().width),
targetd.getPosition().y - (targetd.getContentSize().height),
targetd.getContentSize().width,
targetd.getContentSize().height);
if (CGRect.intersects(projectileRect, targetRect11))
targetdToDelete.add(targetd);
else
projectilesToDelete.add(projectile);
}
for(CCSprite targetd : targetdToDelete){
life--;
lifeLabel(life);
spriteMoveFinished(targetd);
}
这个是在精灵上提供动画:
Random rand = new Random();
CCSprite targetd = CCSprite.sprite("dance.png");
CGSize winSize = CCDirector.sharedDirector().displaySize();
int minX= (int) (targetd.getContentSize().width/2.0f);
int maxX= (int) (winSize.width-targetd.getContentSize().width/2.0f);
int rangeX = maxX-minX;
int actualX = rand.nextInt(rangeX)+minX;
targetd.setPosition(actualX,0 + (targetd.getContentSize().height / 2.0f));
_targetd.add(targetd);
int minDuration = 4;
int maxDuration = 8;
int rangeDuration = maxDuration - minDuration;
int actualDuration = rand.nextInt(rangeDuration) + minDuration;
CCAnimation animation = CCAnimation.animation("dance");
for( int i=1;i<7;i++)
animation.addFrame(String.format("step-%02d.png", i));
CCMoveTo actionMove = CCMoveTo.action(actualDuration, CGPoint.ccp( actualX, winSize.height));
CCAnimate action = CCAnimate.action(3f, animation, false);
CCAnimate action_back = action.reverse();
CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "spriteMoveFinished");
CCFiniteTimeAction parallelAction = CCSpawn.actions( action, actionMove, action_back );
targetd.runAction( parallelAction );
addChild(targetd,2);
喜欢: 值为5,但当我触摸动画精灵值时,我想要的是4,但我发现的结果是2或有时为0。
我做错了什么..请帮我解决这个问题