0

There is no much time delay or gap between random targets fall that is there is a continous move of targets in my cocos2d-android game app, googled alot but could not get any, please help me guys below code is used for target.

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);

} 
samm
  • 482
  • 5
  • 14

1 Answers1

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

This thing make the delay b/w the two sprite. You can change the float value according to u and make this change in the constructor of your Game class.

Akarsh M
  • 1,629
  • 2
  • 24
  • 47
  • thanks for ur reply, this makes the overall speed less, but i need to make a delay between one sprite to other sprite @user2078315 – samm Jul 09 '13 at 13:24
  • make change in the : schudule("sprite_adding_method", float_value_for_time_dely_b/w_same_type_sprite); – Akarsh M Jul 09 '13 at 13:39