精灵的属性Zorder的设置

时间:2022-05-19 19:46:14

1.Zorder是CCSprite从父类CCNode那继承来的protected属性:

class CCNode{

protected:

  int m_nZOrder;                      ///< z-order value that affects the draw order

};

2.影响渲染顺序

a.精灵默认的Zorder值都是0

b.Zorder值越大,越贴在屏幕上面,即越后渲染,越不容易被遮挡

3.与Zorder有关的方法:

  int getZorder();

  void setZorder(int zOrder);

4.代码实现

  CCSprite * man = CCSprite::create("zorder/man.png");
man->setScale(0.3f);
CCSprite * woman = CCSprite::create("zorder/woman.png");
woman->setScale(0.3f);
CCSprite * smallThree = CCSprite::create("zorder/another.png");
smallThree->setScale(0.3f); man->setPosition(ccp(winSize.width / + , winSize.height / - ));
smallThree->setPosition(ccp(winSize.width / , winSize.height / ));
woman->setPosition(ccp(winSize.width / - , winSize.height / + )); addChild(man);
addChild(woman);
addChild(smallThree); /*精灵默认的Zorder都是0*/
CCLog("%d", man->getZOrder());
CCLog("%d", woman->getZOrder());
CCLog("%d", smallThree->getZOrder()); /*Zorder值越大,越贴在屏幕上面,即越后渲染,越不容易被遮挡*/
man->setZOrder();
smallThree->setZOrder();
woman->setZOrder();