O'Reilly logo

Cocos2d-x Cookbook by Akihiro Matsuura

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing a shape

Drawing a shape in Cocos2d-x can be easy using the DrawNode class. If you can draw various shapes using DrawNode, you will to need to prepare textures for such shapes. In this section, you will learn how to draw shapes without textures.

How to do it...

Firstly, you made a DrawNode instance as shown in the following codes. You got a window size as well.

auto size = Director::getInstance()->getWinSize();
auto draw = DrawNode::create();
this->addChild(draw);

Drawing a dot

You can draw a dot by specifying the point, the radius and the color.

draw->drawDot(Vec2(size/2), 10.0f, Color4F::WHITE);
Drawing a dot

Drawing lines

You can draw lines by specifying ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required