CCDrawNode Class Reference

Inherits from CCNode : CCResponder : NSObject
Declared in CCDrawNode.h

Overview

Node that draws dots, segments and polygons. Draws everything in a single batch draw.

The geometry will be saved and batch-drawn, so added primitives do not need to be re-added every frame.

Warning: This node is primarily meant for debug drawing (debug overlays). It does not support changing already added primitives without first removing and re-adding all primitives, which makes modifying the draw node’s state inefficient. For complex vector drawing and entire games built on vector graphics it is strongly recommended to write your own vector rendering node by using CCRenderer (OpenGL or Metal).

Adding Primitives

– drawDot:radius:color:

Adds a dot at a position, with a given radius and color.

- (void)drawDot:(CGPoint)pos radius:(CGFloat)radius color:(CCColor *)color

Parameters

pos

Dot position.

radius

Dot radius.

color

Dot color.

See Also

Declared In

CCDrawNode.h

– drawSegmentFrom:to:radius:color:

Adds a segment with a radius and color.

- (void)drawSegmentFrom:(CGPoint)a to:(CGPoint)b radius:(CGFloat)radius color:(CCColor *)color

Parameters

a

Segment starting point.

b

Segment end point.

radius

Segment radius.

color

Segment color.

See Also

Declared In

CCDrawNode.h

– drawPolyWithVerts:count:fillColor:borderWidth:borderColor:

Draw a convex polygon with a fill color and line color. The polygon winding must be clockwise.

- (void)drawPolyWithVerts:(const CGPoint *)verts count:(NSUInteger)count fillColor:(CCColor *)fill borderWidth:(CGFloat)width borderColor:(CCColor *)line

Parameters

verts

Array of CGPoints, containing the vertices.

count

Number of vertices.

fill

Polygon fill color.

width

Polygon outline width.

line

Polygon outline color.

See Also

Declared In

CCDrawNode.h

Removing all Primitives

– clear

Removes all buffered primitives from the node’s buffer. After calling this the draw node will not draw anything.

- (void)clear

Discussion

Warning: If you need to just change a single primitive, you have to clear the draw node, and re-add all existing primitives that you’ve stored somewhere, with the changes applied. This is of course inefficient, hence the recommendation to use this node primarily for debug drawing.

Declared In

CCDrawNode.h