首页 > 代码库 > 精灵的属性Zorder的设置
精灵的属性Zorder的设置
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 / 2 + 30, winSize.height / 2 - 30)); smallThree->setPosition(ccp(winSize.width / 2, winSize.height / 2)); woman->setPosition(ccp(winSize.width / 2 - 30, winSize.height / 2 + 30)); addChild(man); addChild(woman); addChild(smallThree); /*精灵默认的Zorder都是0*/ CCLog("%d", man->getZOrder()); CCLog("%d", woman->getZOrder()); CCLog("%d", smallThree->getZOrder()); /*Zorder值越大,越贴在屏幕上面,即越后渲染,越不容易被遮挡*/ man->setZOrder(100); smallThree->setZOrder(50); woman->setZOrder(0);
精灵的属性Zorder的设置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。