码迷,mamicode.com
首页 > 其他好文 > 详细

精灵的属性Zorder的设置

时间:2014-11-05 10:41:13      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   div   on   log   

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的设置

标签:style   blog   io   color   os   sp   div   on   log   

原文地址:http://www.cnblogs.com/ttss/p/4075415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!