axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
922 stars 205 forks source link

DrawNode draws in wrong order #1888

Closed NgVThangBz closed 5 months ago

NgVThangBz commented 6 months ago

Looking at the code below, you can see that in the draw node the drawing order will be triangle, point, line: Screenshot 2024-05-07 at 14 51 17 So even if the triangle is added after the point, it is still drawn first, leading to the triangles always being covered by lines,

In my opinion: it would be good if lines, triangles, points are drawn one after another in the order they are added

can check code: DrawNode* _drawNode = DrawNode::create(); Director::getInstance()->getRunningScene()->addChild(_drawNode,100); _drawNode->drawLine(Vec2(200,200),Vec2(500,500),Color4B::RED); _drawNode->drawSolidRect(Vec2(200,200),Vec2(500,500),Color4B::YELLOW);

and result:

Screenshot 2024-05-07 at 15 03 19

aismann commented 6 months ago

Im working on a 'new' DrawNode class (currently available as extension DrawNodeEx). I have seen this "wrong" behavior too. This feature will be on a "next" version.

aismann commented 6 months ago

Workaround: Create an own DrawNode object for each "drawing primitives".

NgVThangBz commented 6 months ago

Workaround: Create an own DrawNode object for each "drawing primitives".

Yes, that's a temporary solution, or can convert line and point into polygons.

aismann commented 6 months ago

Workaround: Create an own DrawNode object for each "drawing primitives".

Yes, that's a temporary solution, or can convert line and point into polygons.

Thats not so easy as you think. There a lot of different scenarios for correct drawing order. @halx99 Please add tag: 'need founding' and anything like: 'workaround exist' and/or 'helpdesk' only

aismann commented 6 months ago

Add a method to set the correct draw order :

    drawNode->drawLine(Vec2(20, 20), Vec2(200, 200), Color4B::RED);
    drawNode->drawSolidRect(Vec2(50, 50), Vec2(150, 150), Color4B::YELLOW);
    drawNode->drawLine(Vec2(30, 20), Vec2(210, 200), Color4B::BLUE);

image

aismann commented 5 months ago

merged/solved with #1914 @NgVThangBz please close it.