addChild设置显示层级

    Size winSize = Director::getInstance()->getWinSize();//获取屏幕大小
    off = Sprite::create("res/CloseNormal.png");
    off->setPosition(Vec2(winSize.width/2, winSize.height/2));//设置图片位置
    off->setScale(0.3);//缩放图片(1为图片正常大小
![
![层级2.png](http://upload-images.jianshu.io/upload_images/1707554-705fc321f9707dcc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
](http://upload-images.jianshu.io/upload_images/1707554-9f8ec0072e75601a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
)
    off->setAnchorPoint(Vec2(0.5, 0));//设置锚点
    this->addChild(off,2);//设置层级关系数值越大越靠上

    rectangular = Sprite::create("res/Button_Public.png");
    rectangular->setPosition(Vec2(winSize.width/2, winSize.height/2));
    rectangular->setScale(0.3);
    rectangular->setAnchorPoint(Vec2(0.5, 0));
    this->addChild(rectangular,3);

    background = Sprite::create("res/HelloWorld.png");
    background->setPosition(Vec2(winSize.width/2, winSize.height/2));
    background->setScale(1.5);
    this->addChild(background);

this->addChild(background);//没设置层级关系默认最下面


addChild设置显示层级_第1张图片
层级.png

如果都没设置层级关系,默认会把最后加入的图片放在最上面


addChild设置显示层级_第2张图片
层级2.png

你可能感兴趣的:(addChild设置显示层级)