Kann man mit einem DrawNode-Objekt ein Rect mit abgerundeten Ecken zeichnen? Ich denke, dass etwas mit Bezier-Kurven möglich ist, aber ich habe einige Versuche gemacht und ich denke, ich kann damit nicht umgehen.Abgerundete Ecken Rect in Cocos 2d-x mit Bezier
bei API Suche Ich habe nur diese zwei Funktionen gefunden:
drawQuadBezier(const Vec2 &origin, const Vec2 &control, const Vec2 &destination, unsigned int segments, const Color4F &color)
drawCubicBezier(const Vec2 &origin, const Vec2 &control1, const Vec2 &control2, const Vec2 &destination, unsigned int segments, const Color4F &color)
[nach Antwort Geändert]
ich die Antwort in Cocos2dx beworben haben, finden vielleicht jemand dies nützlich:
(nur einige Casting getan int, wenn Sie keine hohe Präzision benötigen)
auto MagicConst = 0.552;
auto position = 150;
auto R = 50;
Vec2 TopLeft = Vec2(position, position + R * 2);
Vec2 TopRight = Vec2(position + R * 2, position + R * 2);
Vec2 BottomRight = Vec2(position + R * 2, position);
Vec2 BottomLeft = Vec2(position, position);
Vec2 originTL = Vec2(TopLeft.x, TopLeft.y - R);
Vec2 originTR = Vec2(TopRight.x - R, TopRight.y);
Vec2 originBR = Vec2(BottomRight.x - R, BottomRight.y);
Vec2 originBL = Vec2(BottomLeft.x, BottomLeft.y + R);
Vec2 control1TL = Vec2(TopLeft.x, (int) (TopLeft.y - R * (1 - MagicConst)));
Vec2 control1TR = Vec2((int) (TopRight.x - R * (1 - MagicConst)), TopRight.y);
Vec2 control1BR = Vec2((int) (BottomRight.x - R * (1 - MagicConst)), BottomRight.y);
Vec2 control1BL = Vec2(BottomLeft.x, (int) (BottomLeft.y + R * (1 - MagicConst)));
Vec2 control2TL = Vec2((int) (TopLeft.x + R * (1 - MagicConst)), TopLeft.y);
Vec2 control2TR = Vec2(TopRight.x, (int) (TopRight.y - R * (1 - MagicConst)));
Vec2 control2BR = Vec2(BottomRight.x, (int) (BottomRight.y + R * (1 - MagicConst)));
Vec2 control2BL = Vec2((int) (BottomLeft.x + R * (1 - MagicConst)), BottomLeft.y);
Vec2 destinationTL = Vec2(TopLeft.x + R, TopLeft.y);
Vec2 destinationTR = Vec2(TopRight.x, TopRight.y - R);
Vec2 destinationBR = Vec2(BottomRight.x, BottomRight.y + R);
Vec2 destinationBL = Vec2(BottomLeft.x + R, BottomLeft.y);
auto roundCorner = DrawNode::create();
roundCorner->drawCubicBezier(originTL, control1TL, control2TL, destinationTL, 10, Color4F::RED);
roundCorner->drawCubicBezier(originTR, control1TR, control2TR, destinationTR, 10, Color4F::GREEN);
roundCorner->drawCubicBezier(originBR, control1BR, control2BR, destinationBR, 10, Color4F::YELLOW);
roundCorner->drawCubicBezier(originBL, control1BL, control2BL, destinationBL, 10, Color4F::WHITE);
addChild(roundCorner);
Dies wird produzieren : http://i.stack.imgur.com/mdEOM.png
Jetzt können Sie MagicConst
ändern, um die Ecken zu runden, wie Sie wollen.
Zum Beispiel mit MagicConst = 0.9
: http://i.stack.imgur.com/9V5cr.png
Das ist das Ergebnis, das ich gesucht! ;) (danke @Mbo)
(ich kann leider keine eingebettete Bild Post noch): P
Danke @Mbo Sie öffnete meine Meinung, jetzt bearbeite ich meine Frage mit dem Code in cocos2dx geschrieben, um dies zu ermöglichen;) –