Z-Order with Box2d Debug layer - not working in 3.0 B2?

I added a layer to be a debug layer to my project, drawing the box2d debug info.

	scene->addChild(gameLayer);
	scene->addChild(this);

#if !HIDEBOX2DEBUG
	auto debugLayer = DebugLayer::create();
	scene->addChild(debugLayer);
#endif

but the debug drawing appears behind my ‘gameLlayer’ layer.

Moving the debug add to before adding the gameLayer makes no difference.

Adding ‘setGlobalZOrder’ to the layers also seemed to have no effect.

What am I doing wrong?

Thanks!

Hi, try setting the local zorder. From the setlocalzroder documentation:
“If two nodes have the same LocalZOrder, then the node that was added first to the children’s array will be in front of the other node”.

scene->addChild(gameLayer,0);
scene->addChild(this,1);
scene->addChild(debugLayer,2);

Thanks - but I tried setting local and global, setting before and after adding to the scene and adding the layers to teh scene in different order - but the debug layer still always gets displayed behind the ‘game’ layer.:frowning:

Can you provide an example (classes or project)? Without that it’s difficult to see what is wrong in your code.

@laurentzubiaur I’ll try to put a sample app together to demonstrate - the app with the problem is too large to post!

Debug Layer draws primitive and other shapes with respect of 0 zOrder. So if you want to display everything right then you have to use lower zOrder ( <= -1 ) for your Layer childrens

@vikaspatidar Hmmm - thanks for that info. I think that I did use negative (as well as trying various positive values) but I will check tonight and try again!