Need help with cocos2d-PRKit?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

129 Stars 34 Forks 30 Commits 0 Opened issues


Additions to the fabulous cocos2d-iphone library as provided by Precognitive Research.

Services available


Need anything else?

Contributors list

# 280,948
15 commits
# 451,424
14 commits


PRKit is a library of some small additions to the fantastic cocos2d for iphone project that some people on the cocos2d forums found useful and figured others might like as well.

PRKit was contributed to the open source community by Precognitive Research, LLC.


This is licensed using the same license as cocos2d itself and provided with absolutely no warranty. You are free to use the PRKit code as you wish as long as you keep the license in the source code.

This code uses the excellent Triangulate C++ classes written by John W. Ratcliff.

Release Notes

Version 0.3 (2013-02-24)
  • Fixed issue with Mac OS X and 64 bit (#9)
  • Restructured project into more sensible structure.
Version 0.2 (2013-02-13)
  • Support for cocos2d 2.0 (thanks to Panajev's pull request)
Version 0.1 (2012-02-24)
  • Initial release for cocos2d 1.1.


Download the source and add the files under ''PRKit'' to your project: * PRFilledPolygon.h * PRFilledPolygon.m * PRTriangulator.h * PRRatcliffTriangulator.h * * triangulate.h * triangulate.cpp


Tested with cocos2d 2.0 for iOS and Mac OS X.

Other Documentation

Allen Tan wrote a great tutorial on making a game with PRKit.

Note that the changes to PRKit described in the tutorial are not needed, since they've been merged into the code.

Class Overview


PRFilledPolygon will fill a polygon of arbitrary points with a texture; think of it like using the Polygon tool in Photoshop and then filling it in using the paint bucket tool.

The class inherits from CCNode, so it can be added to your hierarchy as any other class and should respond to position changes like any other node. (Please test and let us know!)

NSMutableArray *polygonPoints = [NSMutableArray arrayWithCapacity:10];
[polygonPoints addObject:[NSValue valueWithCGPoint:ccp(100,100)]];
[polygonPoints addObject:[NSValue valueWithCGPoint:ccp(200,100)]];
[polygonPoints addObject:[NSValue valueWithCGPoint:ccp(300,200)]];
[polygonPoints addObject:[NSValue valueWithCGPoint:ccp(400,300)]];
[polygonPoints addObject:[NSValue valueWithCGPoint:ccp(500,500)]]; 

CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:@"pattern1.png"]; PRFilledPolygon *filledPolygon = [[[PRFilledPolygon alloc] initWithPoints:polygonPoints andTexture:texture] autorelease]; [self addChild:filledPolygon z:0];

You can also change the points on the fly by calling setPoints:

float newY = 75.0f * CCRANDOM_0_1();       
NSArray *points = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:ccp(0,0)], 
    [NSValue valueWithCGPoint:ccp(0,75)],
    [NSValue valueWithCGPoint:ccp(75,newY + 75)],
    [NSValue valueWithCGPoint:ccp(75,0)],
id box = [self getChildByTag:kTagBox];
[box setPoints:points];

The class also supports pluggable PRTriangulator implementations. Just set the triangulator object with something that implements the PRTriangulator protocol.


This is a protocol for pluggable triangulators. The Ratcliff implementation is the only one that ships with PRKit right now, but should you want to write your own, go right ahead -- you only have to implement one method:

- (NSArray *) triangulateVertices:(NSArray *)vertices;

There is a great reference on with links to many different triangulation algorithms.


This implements the PRTriangulator and is the default triangulator supplied for PRKit. It uses Ratcliff's triangulator from flipcode (shipped with the code as triangulator.h and triangulator.cpp).

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.