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