2
我在玩cocos2d,想知道如何給精靈一個圖層深度,這意味着如何讓精靈在其他人的頭頂上?在其他人的頂部繪製cocos2d的精靈
我在玩cocos2d,想知道如何給精靈一個圖層深度,這意味着如何讓精靈在其他人的頭頂上?在其他人的頂部繪製cocos2d的精靈
你可以做這樣的事情:
假設你的類是CCScene
-(id) init
{
if((self=[super init])) {
CCLayer *foreground = [CCLayer node];
CCLayer *background = [CCLayer node];
CCSprite *sprite1 = [CCSprite spriteWithFile:@"sprite1.png"];
CCSprite *sprite2 = [CCSprite spriteWithFile:@"sprite2.png"];
CCSprite *sprite3 = [CCSprite spriteWithFile:@"sprite3.png"];
[sprite1 addChild:sprite2 z:-1]; //This z:-1 means that sprite 2 is behind sprite 1
[foreground addChild:sprite1];
[background addChild:sprite3];
[self addChild:background z:0]; // z:0 is default, you don't need to add it.
[self addChild:foreground z:1]; // z:1 is infront of z:0
}
return self;
}
的子類,你需要學習如何使用該位是z:添加子的參數。如果您添加一個沒有z參數的孩子,孩子會放在最上面。
感謝您的回覆!工作得很好! – Alex