GlobalZOrder is broken is so many ways

GlobalZOrder is broken is so many ways
0.0 0

#1

I am quite surprised how come nobody mention this but GlobalZOrder feature is so broken that I highly recommend others to not use it on the latest version.

I filed a bug a week ago and told about the basic issue in this forum as well. but now I understand the problem is much deeper then what I thought.

The problem in a nutshell -
Using SetGlobalZOrder break many of the features of cocos2dx such as :

  1. TextureRender - when you try to capture a frame using ->visit the output is completely broken. you cant you TextureRender while using GlobalZOrder.

  2. Using Scene transitions - any transitions that are done over a globalZOrder scene is broken.some elements are not affected by the transition. for example, a fadeout transition may still keep some of the nodes visible while tranisition applied.

Having said that, it seems that globalZOrder was added to the code but was not treated well with other features of cocos2dx. I highly suggest you warn people about it because now that I used it, it is a huge pain to go back.


#2

Hmm. I will check GitHub and talk to engineering.


#3

Please do. this is really a huge problem. I have seen others complain about it in different scenarios. this is a huge problem and making global Z Order (which is blessed) useless.


#4

go to ccnode.cpp

comment these lines in processParentFlags() **edited
if (!isVisitableByVisitingCamera())
return parentFlags;

i hope this fixes the problem…I’ve reported this issue many times


#5

did this work? @Nuno147


#6

No . it didn’t :frowning:


#7

I think this may solve the TextureRender issue. but I currently trying to solve the transition issues ?


#8

didn’t solve the texturer renderer as well. I will create a simple project that demonstrates the problem(s).


#9

Here is a simple project I made to show the problem :

when you run it you will see the standard cocos2dx sample. however, I just did 2 modifications:

  1. When clicking the close button on the screen instead of closing the app it will do :
    Size winSize = Director::getInstance()->getWinSize();

    CCRenderTexture *rt = CCRenderTexture::create(winSize.width, winSize.height);

    rt->begin();
    CCDirector::sharedDirector()->getRunningScene()->visit();
    rt->end();

    rt->getSprite()->setAnchorPoint(Point(0, 0));
    rt->setPosition(Point(-50, -50));
    addChild(rt, 1000);

basically, when clicking it you should see the screen been cloned and with 50 pixels offset. so you should see two images.

  1. I add the line
    // add the sprite as a child to this layer
    this->addChild(sprite);
    sprite->setGlobalZOrder(1);

when you remove this line everything works perfectly. but if you keep it, the whole screen capturing is completely messed up. (just run and see).

it seems that the vist function decides not to draw the image because of some reason. the same problem goes when running transitions.


#10

What version of cocos2d-x are you using? thanks for the project.


#11

3.16 which is the latest release.


#12

the .zip from our website?


#13

yes. from your website.


#14

OK, checking out the v3 branch of our GitHub repo may contain a fix. I don’t know if it does, but worth a shot. I am going to ask the engineering team to look at this thread too.


#15

@Nuno147 thanks for reporting the issue. global z order is not used so much, that’s why it has issues. I will take a look now.


#16

@Nuno147 i don’t use your zip file, just copy the modification you mentioned above. After invoking sprite->setGlobalZOrder(1);, closed menu item is hidden, how can you click it?


#17

First thank you so much for taking a look into this.

On my end, the sprite isn’t over the button so I am not sure what is the problem on your end.

This is the picture before clicking while ZOrder is ON :
image

This is after clicking with ZOrder ON:
image

This is when ZOrder OFF and button was clicked (Expected result):
image

Btw, there is another issue I found which you can see in the picture (notice the title bar is over the text). it cause other issues with touch clicks but leave this for now :slight_smile:


#18

It is because i used cpp-empty-test to reproduce the issue, and the picture is big enough to fill the screen, after setting sprite’s global z order to 1, it is drawn after menu item, so it will hide the menu button.

And i fixed the issue in https://github.com/cocos2d/cocos2d-x/pull/18629.


#19

Thanks !!! I’ll try it out and let you know.