用FOR,和数组显示多个精灵并设置位置

来源:互联网 发布:bizhub7622扫描软件 编辑:程序博客网 时间:2024/06/05 09:42
-(id) init {if((self=[super init])) {CGSize winSize=[CCDirector sharedDirector].winSize;[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGB565];background=[CCSprite spriteWithFile:@"blue-shooting-stars.png"];background.anchorPoint=ccp(0,0);[self addChild:background];[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_Default];movableSprites=[[NSMutableArray alloc] init];NSArray*images=[NSArray arrayWithObjects:@"bird.png",@"cat.png",@"dog.png",@"turtle.png", nil];for(inti=0; i<images.count;++i) {NSString*image=[images objectAtIndex:i];CCSprite*sprite=[CCSprite spriteWithFile:image];floatoffsetFraction=((float)(i+1))/(images.count+1);sprite.position=ccp(winSize.width*offsetFraction, winSize.height/2);[self addChild:sprite];[movableSprites addObject:sprite];}}returnself;}