Coder Social home page Coder Social logo

xperienced / cocos2d-prkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from panajev/prkit

0.0 1.0 0.0 778 KB

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

Home Page: http://precognitiveresearch.com

C++ 32.90% Objective-C 67.10%

cocos2d-prkit's Introduction

PRKit

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.

License

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.

Installation

Download the source and add the files under ''PRKit'' to your project:

  • PRFilledPolygon.h
  • PRFilledPolygon.m
  • PRTriangulator.h
  • PRRatcliffTriangulator.h
  • PRRatcliffTriangulator.mm
  • triangulate.h
  • triangulate.cpp

Class Overview

PRFilledPolygon

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)],
    nil];
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.

PRTriangulator

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 vterrian.org with links to many different triangulation algorithms.

PRRatcliffTriangulator

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).

cocos2d-prkit's People

Contributors

asinesio avatar panajev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.