有没有一种干净有效的方法来创建任意数量的相同 CCSprite?
我真的只需要一个标签来引用它们以便以后删除。
例如,在我的游戏中,我在 HUD 中显示生命数:
- (void)displayOneLife
{
CGPoint positionOne = ccp(90, 450);
CCSprite *life1 = [CCSprite spriteWithFile:@"life.png"];
[life1 setPosition:positionOne];
[life1 setScale:0.5f];
[self addChild:life1 z:5 tag:1];
}
- (void)displayTwoLives
{
CGPoint positionOne = ccp(90, 450);
CGPoint positionTwo = ccp(105, 450);
CCSprite *life1 = [CCSprite spriteWithFile:@"life.png"];
CCSprite *life2 = [CCSprite spriteWithFile:@"life.png"];
[life1 setScale:0.5f];
[life2 setScale:0.5f];
[life1 setPosition:positionOne];
[life2 setPosition:positionTwo];
[self addChild:life1 z:5 tag:1];
[self addChild:life2 z:5 tag:2];
}
- (void)displayThreeLives
{
CGPoint positionOne = ccp(90, 450);
CGPoint positionTwo = ccp(105, 450);
CGPoint positionThree = ccp(120, 450);
CCSprite *life1 = [CCSprite spriteWithFile:@"life.png"];
CCSprite *life2 = [CCSprite spriteWithFile:@"life.png"];
CCSprite *life3 = [CCSprite spriteWithFile:@"life.png"];
[life1 setPosition:positionOne];
[life2 setPosition:positionTwo];
[life3 setPosition:positionThree];
[life1 setScale:0.5f];
[life2 setScale:0.5f];
[life3 setScale:0.5f];
[self addChild:life1 z:5 tag:1];
[self addChild:life2 z:5 tag:2];
[self addChild:life3 z:5 tag:3];
}