cocos2d-android中目标之间的时间延迟

时间:2013-07-05 07:03:21

标签: android cocos2d-iphone cocos2d-android

随机目标之间没有太多的时间延迟或差距,因为在我的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);

} 

1 个答案:

答案 0 :(得分:1)

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

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