How to draw primitives on top of all layers and sprites?

Seems that all the primitives from all the layers is being drawn according to their Z order, then the same is being done for the sprites. Therefore primitives are always under the sprites. How to draw primitives on top of all layers and sprites?

You can use an alternative to the draw primitives. check DrawNode

What about this problem in general? http://stackoverflow.com/questions/22288222/primitives-and-sprites-z-index-in-cocos2d-x-3-0-is-not-consistent

Did you use cocos2d-x 3.0beta2, me too encountering the same problem.

I have a class inherit Node, and override draw with DrawPrimitives draw command but whatever z order i give it when addchild, it draw at the bottom of everything else.

`class Myclass : public Node
{
void draw() { DrawPrimitives::drawLine(…[2 points to draw]…); }
}

//HelloworldScene.cpp
bool init() {
…//code to init game
Sprite * bg = Sprite::create(“bg.png”);
bg->setPosition(Point(_screenSize.width * 0.5f, _screenSize.height * 0.5f));
this->addChild(bg, 0)

Myclass mc = Myclass::create();
this->addChild(mc, 100) //or whatever z order, nothing changes, it will draw under bg so if bg is background sprite, i cant see my line drawn by mc.
`

I thinks this is cocos2d-x 3.0 bugs, anyone using the lower version pls confirm this problem

Yes yes! I hope this is a bug and not done intentionally. But I have noticed that primitives understand the order between each other. So if we imagine a tree-hierarchy of primitives and sprites, then we should note that they are different trees. And first primitives hierarchy is being drawn then sprites, therefore the lowest sprite is on the highest primitive.

it’s a bug, and it was already corrected. version 3.0 RC fixes this.

Where I can download RC version? The latest I see is beta 2 in which I have found the bug.

I’m using the version v3.0 RC0 and have this problem still, all my primitives are drawn under the background. If I don’t create my background I can see all of them.

@pccsoares wrote:

it’s a bug, and it was already corrected. version 3.0 RC fixes this.

Are you sure? couldn’t see mention in release notes, although I haven’t had a chance to test it yet… seem to be conflicting tales as to whether it is fixed or not

From what I have gleaned, the ‘correct’ way tp get this to work is to use something like

	_customCommand.init(_globalZOrder);
	_customCommand.func = CC_CALLBACK_0(WorldLayer::drawSubterrain, this);
	Director::getInstance()->getRenderer()->addCommand(&_customCommand);

in your draw() method
where _customCommand is

	CustomCommand _customCommand;

and the method you want to execute is (in my case above)

void WorldLayer::drawSubTerrain()

Due to the new renderer on 3.0, I think the CustomCommand method is the way to go. I replied to a post here with an example:
http://stackoverflow.com/a/22724319/1468700