
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 1.12 KB | hits: 10 | expires: Never
Cocos2d random issue
CCSprite *ladyBug = [CCSprite spriteWithFile:@"Bug-1.png"];
// Determine where to spawn the target along the Y axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minY = ladyBug.contentSize.width/2;
int maxY = winSize.width - ladyBug.contentSize.width/2;
int rangeY = maxY - minY;
int random = (arc4random() % rangeY) + minY;
// Create the target slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
ladyBug.position = ccp(random, -(ladyBug.contentSize.height));
bugIndexes++;
ladyBug.tag = bugIndexes;
[self addChild:ladyBug];
// Determine speed of the target
int minDuration = 2.0;
int maxDuration = 3.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp( random , winSize.height + ladyBug.contentSize.height)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[ladyBug runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];