0

在我的 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);

} 
4

1 回答 1

1
this.schedule("Method_name", 6.0f);

这件事使两个精灵的延迟黑白。您可以根据 u 更改浮点值,并在 Game 类的构造函数中进行此更改。

于 2013-07-09T04:56:26.117 回答