Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Cocos2d-x cookbook

You're reading from   Cocos2d-x cookbook Over 50 hands-on recipes to help you efficiently administer and maintain your games with Cocos2d-x

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781783284757
Length 254 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Akihiro Matsuura Akihiro Matsuura
Author Profile Icon Akihiro Matsuura
Akihiro Matsuura
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Cocos2d-x FREE CHAPTER 2. Creating Sprites 3. Working with Labels 4. Building Scenes and Layers 5. Creating GUIs 6. Playing Sounds 7. Working with Resource Files 8. Working with Hardware 9. Controlling Physics 10. Improving Games with Extra Features 11. Taking Advantages Index

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 lines

You can draw lines by specifying the starting point, the destination point, and the color. A 1px thick line will be drawn when you use the drawLine method. If you want to draw thicker lines, use the drawSegment method with a given radius.

draw->drawLine(Vec2(300, 200), Vec2(600, 200), Color4F::WHITE);
draw->drawSegment(Vec2(300, 100), Vec2(600, 100), 10.0f,
Color4F...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images