在我的 cocos2d-android 游戏应用程序中,随机目标下降之间没有太多的时间延迟或间隙,目标不断移动,谷歌搜索了很多但没有得到任何东西,请帮助我下面的代码用于目标。
Random rand = new Random();
CCSprite target = CCSprite.sprite("target.png");
// Determine where to spawn the target along the Y axis
CGSize winSize = CCDirector.sharedDirector().displaySize();
int minX = (int)(target.getContentSize().width / 2.0f);
int maxX = (int)(winSize.width - target.getContentSize().width / 2.0f);
int rangeX = maxX - minX;
int actualX = rand.nextInt(rangeX) + minX;
// Create the target slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
// target.setPosition(getContentSize().width + (target.getContentSize().width / 2.0f), actualX);
target.setPosition(actualX, winSize.height + target.getContentSize().height);
addChild(target);
target.setTag(1);
_targets.add(target);
// Determine speed of the target
int minDuration = 20;
int maxDuration = 30;
int rangeDuration = maxDuration - minDuration;
int actualDuration = rand.nextInt(rangeDuration) + minDuration;
// Create the actions
//CCMoveTo actionMove = CCMoveTo.action(actualDuration, CGPoint.ccp(-target.getContentSize().width / 2.0f, actualX));
CCMoveTo actionMove = CCMoveTo.action(actualDuration, CGPoint.ccp(actualX, - target.getContentSize().height));
CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "spriteMoveFinished");
CCSequence actions = CCSequence.actions(actionMove, actionMoveDone);
target.runAction(actions);
}