Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.12 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Cocos2d random issue
  2. CCSprite *ladyBug = [CCSprite spriteWithFile:@"Bug-1.png"];
  3.  
  4. // Determine where to spawn the target along the Y axis
  5. CGSize winSize = [[CCDirector sharedDirector] winSize];
  6. int minY = ladyBug.contentSize.width/2;
  7. int maxY = winSize.width - ladyBug.contentSize.width/2;
  8. int rangeY = maxY - minY;
  9. int random = (arc4random() % rangeY) + minY;
  10.  
  11. // Create the target slightly off-screen along the right edge,
  12. // and along a random position along the Y axis as calculated above
  13. ladyBug.position = ccp(random, -(ladyBug.contentSize.height));
  14. bugIndexes++;
  15. ladyBug.tag = bugIndexes;
  16. [self addChild:ladyBug];
  17.  
  18.  
  19. // Determine speed of the target
  20. int minDuration = 2.0;
  21. int maxDuration = 3.0;
  22. int rangeDuration = maxDuration - minDuration;
  23. int actualDuration = (arc4random() % rangeDuration) + minDuration;
  24.  
  25. // Create the actions
  26. id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp( random , winSize.height + ladyBug.contentSize.height)];  
  27. id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
  28. [ladyBug runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];