O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

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 glPrimitives

Cocos2d uses openGLES, which is a graphics library that enables objects to be displayed onscreen. In fact, all the drawing that we have done until now uses this library. Cocos2d also gives you basic access to glPrimitives, which can be used to create basic shapes, such as circles, squares, rectangles, and so on.

Getting ready

Let's take a look at a few of the examples now. We will begin by creating a simple circle.

How to do it…

Right after adding the hero node, we will add the following code:

//drawDotNode
CCDrawNode* dotNode = [CCDrawNode node];
CCColor* red = [CCColorcolorWithRed:1.0fgreen:0.0fblue:0.0f];
[dotNodedrawDot:CGPointMake(winSize.width/2, winSize.height/2) radius: 10.0fcolor:red];
[selfaddChild:dotNode];

glPrimitives ...

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