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
868 stars 195 forks source link

DrawNode: setLineWitdh() is no longer working #1411

Closed aismann closed 11 months ago

aismann commented 11 months ago

Steps to Reproduce: cpp-tests->31:Node:Draw>GitHub Issue #11942 (axmol #137)"

Wrong: Latest build: image

Works: Thats a older version image

halx99 commented 11 months ago

Not recommand use setLineWith because the render backend opengl & metal have diferrent behavior:

joprice commented 7 months ago

I hit this as well and found a workaround by taking the drawSolidCircle code and calling drawPolygon instead ofdrawSolidPoly and passing thickness along:

 static void drawCircle(DrawNode &node, const Vec2 &center, float radius, float angle, int segments,
                         float scaleX, float scaleY, const Color4F &color, float thickness) {
    const float coef = 2.0f * (float)M_PI / static_cast<float>(segments);

    Vec2 *vertices = new (std::nothrow) Vec2[segments];
    if (vertices == nullptr)
      return;

    for (unsigned int i = 0; i < segments; i++) {
      float rads = static_cast<float>(i) * coef;
      float j = radius * cosf(rads + angle) * scaleX + center.x;
      float k = radius * sinf(rads + angle) * scaleY + center.y;

      vertices[i].x = j;
      vertices[i].y = k;
    }
    node.drawPolygon(vertices, segments, Color4F(), thickness, color);

    CC_SAFE_DELETE_ARRAY(vertices);
  }

Might be of help to someone, or could perhaps become a new helper if it seems useful enough.