Help Please - Spine Layers not being rendered in order

Hi,

Im using the latest version of cocos2dx v3 from github, for a week now a issue has occurred where layers do not always seem to be rendered in correct order, mostly labels and spine layers.

For example…

Size visibleSize = Director::getInstance()>getVisibleSize;
LayerColor *layerColor = LayerColor::create);
layerColor
>setContentSize(visibleSize);
layerColor~~>setPosition;
this~~>addChild(layerColor);

CCSkeletonAnimation *splashAnim = CCSkeletonAnimation::createWithFile(“spine/splash.json”, “spine/splash.atlas”);
splashAnim~~>setAnimation;
splashAnim~~>setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
splashAnim~~>setScale;
this~~>addChild(splashAnim);

the spine animation appears to be behind the layer colour, adding Z orders to the addChild’s doesn’t seem to make a difference, removing the this->addChild(layerColor); the spine animation is displayed.

Anyone have any ideas, still appears to be an issue?

I found similar issue. But this only happens when I call “setZOrder” and “reorderChild” function.

Say there are 40 nodes on our layer, 20 nodes (T) on top of 20 other nodes (B). Sometime the B nodes appears on top of T nodes after I call “setZOrder” and then “reorderChild” function.
To “fix” the case, I add extra dummy nodes to group the nodes

Parent
|-T,T,T,T,B,B,B

to

Parent
|-Node1
  |-T,T,T,T
|-Node2
  |-B,B,B

See if it helps.

Don’t think its the case in my scenario as only have the two nodes in a slash screen like this, the problem only seems to show itself with spine layers and label layers…

    #include "SplashScene.h"
    #include "cocos-ext.h"
    #include 
    #include "MenuScene.h"

    using namespace cocos2d;
    using namespace extension;

    Scene* SplashScene::scene()
    {
        Scene *scene = Scene::create();
        SplashScene *layer = SplashScene::create();
        scene->addChild(layer);
        return scene;
    }

    bool SplashScene::init()
    {
        if (!Layer::init())
        {
            return false;
        }

        Size visibleSize = Director::getInstance()->getVisibleSize();
        LayerColor *layerColor = LayerColor::create(Color4B(255, 255, 255, 255));
        layerColor->setContentSize(visibleSize);
        layerColor->setPosition(Point::ZERO);
        this->addChild(layerColor);

        spine::CCSkeletonAnimation *splashAnim = spine::CCSkeletonAnimation::createWithFile("spine/splash.json", "spine/splash.atlas");
        splashAnim->setAnimation(0, "animation", true);
        splashAnim->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
        splashAnim->setScale(0.25);
        this->addChild(splashAnim);

        this->runAction(Sequence::create(DelayTime::create(3.0f), CallFunc::create(CC_CALLBACK_0(SplashScene::splashDone, this)), NULL));

        return true;
    }

    void SplashScene::splashDone()
    {
        Director::getInstance()->replaceScene(TransitionCrossFade::create(1, MenuScene::scene()));
    }

Ok found the problem and a temp fix, in CCSkeleton i had to change one of the drawQuads to…

    if (textureAtlas) {

        auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);

        kmMat4 mv;
        kmGLGetMatrix(KM_GL_MODELVIEW, &mv);

        _quadCommand.init(0,
                          _vertexZ,
                          textureAtlas->getTexture()->getName(),
                          shader,
                          getBlendFunc(),
                          textureAtlas->getQuads(),
                          textureAtlas->getTotalQuads(),
                          mv);
        Director::getInstance()->getRenderer()->addCommand(&_quadCommand);

        textureAtlas->removeAllQuads();
    }

Doing the above made spine render in correct order, how ever not sure how to properly implement for the remaining textureAtlas->drawQuads();, any help appreciated :slight_smile: