Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
PathNode Class Reference

#include <CUPathNode.h>

Inheritance diagram for PathNode:
TexturedNode

Public Member Functions

void setStroke (float stroke)
 
float getStroke () const
 
void setClosed (bool closed)
 
bool getClosed () const
 
void setJoint (Poly2::Joint joint)
 
Poly2::Joint getJoint () const
 
void setCap (Poly2::Cap cap)
 
Poly2::Cap getCap () const
 
virtual std::string getDescription () const override
 
virtual void setPolygon (const Poly2 &poly) override
 
virtual void setPolygon (const Rect &rect) override
 
virtual void draw (Renderer *renderer, const Mat4 &transform, uint32_t flags) override
 
virtual ~PathNode (void)
 
- Public Member Functions inherited from TexturedNode
virtual void setTexture (const std::string &filename)
 
virtual void setTexture (Texture2D *texture) override
 
virtual Texture2D * getTexture () const override
 
virtual void setPolygon (float *vertices, int size, int offset=0)
 
const Poly2getPolygon () const
 
virtual void shiftPolygon (float dx, float dy)
 
const Rect & getBoundingRect () const
 
void setBlendFunc (const BlendFunc &blendFunc) override
 
const BlendFunc & getBlendFunc () const override
 
virtual void setOpacityModifyRGB (bool modify) override
 
virtual bool isOpacityModifyRGB (void) const override
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual ~TexturedNode (void)
 
virtual bool init () override
 
virtual bool init (float *vertices, int size, int offset=0)
 
virtual bool init (const Poly2 &poly)
 
virtual bool init (const Rect &rect)
 
virtual bool initWithFile (const std::string &filename)
 
virtual bool initWithFile (const std::string &filename, float *vertices, int size, int offset=0)
 
virtual bool initWithFile (const std::string &filename, const Poly2 &poly)
 
virtual bool initWithFile (const std::string &filename, const Rect &rect)
 
virtual bool initWithTexture (Texture2D *texture)
 
virtual bool initWithTexture (Texture2D *texture, float *vertices, int size, int offset=0)
 
virtual bool initWithTexture (Texture2D *texture, const Poly2 &poly)
 
virtual bool initWithTexture (Texture2D *texture, const Rect &rect)
 

Static Public Member Functions

static PathNodecreate ()
 
static PathNodecreateWithVertices (float *vertices, int size, float stroke, bool closed=true)
 
static PathNodecreateWithPoly (const Poly2 &poly, float stroke, bool closed=true)
 
static PathNodecreateWithRect (const Rect &rect, float stroke)
 
static PathNodecreateWithLine (const Vec2 &origin, const Vec2 &dest, float stroke)
 
static PathNodecreateWithCircle (const Vec2 &center, const Size &size, float stroke, unsigned int segments)
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: PathNode(float stroke
 
CC_CONSTRUCTOR_ACCESS bool closed =true)
 
- Public Attributes inherited from TexturedNode
CC_CONSTRUCTOR_ACCESS __pad0__: TexturedNode(void)
 

Protected Member Functions

virtual void generateRenderData () override
 
- Protected Member Functions inherited from TexturedNode
TrianglesCommand::Triangles & allocTriangles (const Poly2 &poly)
 
void clearRenderData ()
 
void updateColor () override
 
void updateBlendFunc ()
 
void updateTextureCoords ()
 

Protected Attributes

Poly2 _extrusion
 
bool _closed
 
float _stroke
 
Poly2::Joint _joint
 
Poly2::Cap _endcap
 
- Protected Attributes inherited from TexturedNode
Texture2D * _texture
 
Poly2 _polygon
 
BlendFunc _blendFunc
 
bool _insideBounds
 
bool _opacityModifyRGB
 
TrianglesCommand _command
 
TrianglesCommand::Triangles _triangles
 
bool _flipHorizontal
 
bool _flipVertical
 

Detailed Description

Scene graph node to represent a path with width.

This class uses the Cocos2D rendering pipeline to batch graphics information into a single mesh (with one drawing call), whenever possible. Changes to the textures, or drawing a line instead of a solid shape will require a new batch. You should play with your scene graph ordering to best improve performance.

Because paths have width, it is natural to texture them. However, generally you will only want to create a path with the degenerate texture (to draw a solid, colored path). Hence, none of the static constructors take a texture. You are free to update the texture after creation, if you wish.

The polygon is specified in image coordinates. Image coordinates are different from texture coordinates. Their origin is at the bottom-left corner of the file, and each pixel is one unit. This makes specifying to polygon more natural for irregular shapes.

This means that a polygon with vertices (0,0), (width,0), (width,height), and (0,height) would be identical to a sprite node. However, a polygon with vertices (0,0), (2*width,0), (2*width,2*height), and (0,2*height) would tile the sprite (given the wrap settings) twice both horizontally and vertically.

The content size of this node is defined by the size (but not the offset) of the bounding box. The anchor point is relative to this content size. The default anchor point in TexturedNode is (0.5, 0.5). This means that a uniform translation of the polygon (in contrast to the node itself) will not move the shape on the the screen. Instead, it will just change the part of the texture it uses.

For example, suppose the texture has given width and height. We have one polygon with vertices (0,0), (width/2,0), (width/2,height/2), and (0,height/2). We have another polygon with vertices (width/2,height/2), (width,height/2), (width,height), and (width/2,height). Both polygons would create a rectangle of size (width/2,height/2). centered at the node position. However, the first would use the bottom left part of the texture, while the second would use the top right.

Constructor & Destructor Documentation

virtual PathNode::~PathNode ( void  )
inlinevirtual

Releases all resources allocated with this sprite.

After this is called, the polygon and drawing commands will be deleted and no longer safe to use.

Member Function Documentation

NS_CC_BEGIN PathNode * PathNode::create ( )
static

Creates an empty path node.

The underlying polygon is empty, and must be set via setPolygon.

Returns
An autoreleased path node
PathNode * PathNode::createWithCircle ( const Vec2 &  center,
const Size &  size,
float  stroke,
unsigned int  segments 
)
static

Creates a wireframe that is an ellipse with given the center and dimensions.

The wireframe will show the boundary, not the circle tesselation.

Parameters
centerThe ellipse center point
sizeThe size of the ellipse
strokeThe width of the path
segmentsThe number of segments to use
Returns
An autoreleased path node
PathNode * PathNode::createWithLine ( const Vec2 &  origin,
const Vec2 &  dest,
float  stroke 
)
static

Creates a path that is a line from origin to destination.

Parameters
originThe line origin
destThe line destination
strokeThe width of the path
Returns
An autoreleased path node
PathNode * PathNode::createWithPoly ( const Poly2 poly,
float  stroke,
bool  closed = true 
)
static

Creates a path with the given polygon and stroke width.

The path traverses the vertices of the polygon in order, regardless of any tesselation (e.g. the indices are ignored). The path is closed by default.

Parameters
polyThe polygon for the wireframe path
strokeThe width of the path
closedWhether or not the polygon path is closed.
Returns
An autoreleased path node
PathNode * PathNode::createWithRect ( const Rect &  rect,
float  stroke 
)
static

Creates a path with the given rect and stroke width.

The path will traverse the corners of the rectangle, and the traversal is closed.

Parameters
rectThe rectangle for the wireframe path
strokeThe width of the path
Returns
An autoreleased path node
PathNode * PathNode::createWithVertices ( float *  vertices,
int  size,
float  stroke,
bool  closed = true 
)
static

Creates a path with the given vertices and stroke width.

The path traverses the vertices in order, regardless of any tesselation. The path is closed by default.

Parameters
verticesThe vertices forming the wireframe path
sizeThe number of elements in vertices
strokeThe width of the path
closedWhether or not the polygon path is closed.
Returns
An autoreleased path node
void PathNode::draw ( Renderer *  renderer,
const Mat4 &  transform,
uint32_t  flags 
)
overridevirtual

Sends drawing commands to the renderer

This method is overridden from Node, to provide the custom commands. Wireframes are drawn to the Wireframe mesh (which is different from the Triangle mesh used for solid shapes) to cut down on the number of drawing calls.

Parameters
rendererReference to the render thread
transformThe accumulated transform from the parent
flagsSpecialized Cocos2d drawing flags
void PathNode::generateRenderData ( )
overrideprotectedvirtual

Allocate the render data necessary to render this node.

This method allocates the Triangles data used by the TrianglesCommand in the rendering pipeline.

Allocate the wireframe data necessary to render this node.

This method allocates the Wireframe data used by the WireframeCommand in the rendering pipeline.

Reimplemented from TexturedNode.

Poly2::Cap PathNode::getCap ( ) const
inline

Returns the cap shape at the ends of the path.

Returns
the cap shape at the ends of the path.
bool PathNode::getClosed ( ) const
inline

Returns whether the path is closed.

Returns
whether the path is closed.
std::string PathNode::getDescription ( ) const
overridevirtual

Returns a string description of this object

This method is useful for debugging.

Returns
a string description of this object
Poly2::Joint PathNode::getJoint ( ) const
inline

Returns the joint type between path segments.

Returns
the joint type between path segments.
float PathNode::getStroke ( ) const
inline

Returns the stroke width of the path.

Returns
the stroke width of the path.
void PathNode::setCap ( Poly2::Cap  cap)

Sets the cap shape at the ends of the path.

Parameters
capCap shape at the ends of the path.
void PathNode::setClosed ( bool  closed)

Sets whether the path is closed.

Parameters
closedWhether the path is closed.
void PathNode::setJoint ( Poly2::Joint  joint)

Sets the joint type between path segments.

Parameters
jointJoint type between path segments
void PathNode::setPolygon ( const Poly2 poly)
overridevirtual

Sets the polygon to the given one in texture space.

Parameters
polyThe polygon to texture

Sets the texture polygon to the given one in image space.

Parameters
polyThe polygon to texture

Reimplemented from TexturedNode.

void PathNode::setPolygon ( const Rect &  rect)
overridevirtual

Sets the texture polygon to one equivalent to the given rect.

The rectangle will be converted into a Poly2. Unless you are constructing wireframes, there is little benefit to using a TexturedNode in this way over a normal Sprite. The option is here only for completion.

Parameters
rectThe rectangle to texture

Reimplemented from TexturedNode.

void PathNode::setStroke ( float  stroke)

Sets the stroke width of the path.

Parameters
strokeThe stroke width of the path

Member Data Documentation

bool PathNode::_closed
protected

Whether or not the polygon path is closed.

Poly2::Cap PathNode::_endcap
protected

The shape of the two end caps of the path.

Poly2 PathNode::_extrusion
protected

The extrusion polygon, when stroke > 0

Poly2::Joint PathNode::_joint
protected

The joint between segments of the path.

float PathNode::_stroke
protected

The stroke width of this path.


The documentation for this class was generated from the following files: