how to generate random bubbles from array of sprites in cocos2d?
Posted
by
prakash s
on Game Development
See other posts from Game Development
or by prakash s
Published on 2012-10-08T08:59:17Z
Indexed on
2012/10/08
9:48 UTC
Read the original article
Hit count: 303
cocos2d
I am devoloping the bubble shooter game in cocos2d how to generate random bubbles from array of sprites here is my code
(void)addTarget {
CGSize winSize = [[CCDirector sharedDirector] winSize];
//CCSprite *target = [CCSprite spriteWithFile:@"3.png" rect:CGRectMake(0, 0, 256, 256)];
NSMutableArray * movableSprites = [[NSMutableArray alloc] init];
NSArray *images = [NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png", @"4.png",@"5.png",@"1.png",@"5.png", @"3.png", nil];
for(int i = 0; i < images.count; ++i) {
NSString *image = [images objectAtIndex:i];
// generate random number based on size of array (array size is larger than 10)
CCSprite*target = [CCSprite spriteWithFile:image];
float offsetFraction = ((float)(i+1))/(images.count+1);
target.position = ccp(winSize.width*offsetFraction, winSize.height/2);
target.position = ccp(350*offsetFraction, 460);
[self addChild:target];
[movableSprites addObject:target];
//[target runAction:];
id actionMove = [CCMoveTo actionWithDuration:10 position:ccp(winSize.width/2,winSize. height/2)];
This code generating bubbles with *.png colour bubbles but i want to generate randomly because for shooting the bubbles by shooter class help me please
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
}
}
© Game Development or respective owner