How to draw simple rect with cocos2d-x v3.0

早过忘川 提交于 2019-12-08 05:17:21

问题


In cocos2d-x 3.0 dont work ccDrawSolidRect. 3.0 api have class Rect, but i cant find documentation about it. How to draw simple color rect with cocos2d-x 3.0?


回答1:


You can use void drawRect( Point origin, Point destination ); declared in CCDrawingPrimitives.

Call this method inside draw() method of any subclass of CCNode like:

void TestNode::draw() {
    drawRect(Point::Point(10,10), Point::Point(40,40));
}



回答2:


You can try

DrawPrimitives::drawRect(const cocos2d::Point origin, const cocos2d::Point destination);



回答3:


You can also use this code snippet:

auto rectNode = DrawNode::create();
Vec2 rectangle[4];
rectangle[0] = Vec2(-50, -50);
rectangle[1] = Vec2(50, -50);
rectangle[2] = Vec2(50, 50);
rectangle[3] = Vec2(-50, 50);

Color4F white(1, 1, 1, 1);
rectNode->drawPolygon(rectangle, 4, white, 1, white);
this->addChild(rectNode);

Reference: cocso2d-x forum



来源:https://stackoverflow.com/questions/19431922/how-to-draw-simple-rect-with-cocos2d-x-v3-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!