SHPolygon (OLD VERSION)

type:
extension
author:
Shilo White
description:
A simple customizable polygon.
lastupdate:
2011-03-19
compatible:
v1.X
tag:
polygon, shape, primitive
homepage:
https://gist.github.com/878014
download:
https://gist.github.com/gists/878014/download
sample:
http://shilo.coarsemode.com/sparrow/extensions/shpolygon/StarFieldSample.zip

Description

SHPolygon class will allow you to create primitive polygon shapes on the stage. You can set the number of sides, customize inner color, outer color, border color, change the border width, toggle the fill and border, set the center x, center y, change the radius x, radius y, rotate around center, and everything else you can do with an SPDisplayObject.

Sample

Example

//add a triangle with default sides: 3
SHPolygon *triangle = [SHPolygon polygonWithWidth:100 height:100];
[self addChild:triangle];
 
//add a diamond shape
SHPolygon *diamond = [SHPolygon polygonWithWidth:320 height:480];
diamond.sides = 4;
[self addChild:diamond];
 
//add a star and center it on stage
SHPolygon *star = [SHPolygon polygonWithWidth:320 height:320];
star.sides = 5;
star.innerColor = 0xffffff;
star.outerColor = 0x000000;
star.centerX = 320/2;
star.centerY = 480/2;
[self addChild:star];
 
//add a circle with default width and height: 32
SHPolygon *circle = [SHPolygon polygon];
circle.sides = 360;
[self addChild:circle];

Instructions

To add into your Sparrow project

  1. Download the source files here: https://gist.github.com/gists/878014/download
  2. Open your desired Sparrow project
  3. Drag and drop the files into the “Groups & Files” pane
  4. Open “Game.h”
  5. Include the extension:
    #include "SHPolygon.h"
  6. Save “Game.h”

To add directly into Sparrow source

  1. Download the source files here: https://gist.github.com/gists/878014/download
  2. Save the files into Sparrow's “/Classes/” directory
    • Example: “/sparrow/src/Classes/”
  3. Navigate back one directory and open “Sparrow.xcodeproj”
    • Example: “/sparrow/src/Sparrow.xcodeproj”
  4. Inside the “Groups & Files” pane, locate the “Display” group folder
    • Example: “Sparrow → Classes → Display”
  5. Right click the “Display” group folder and click “Add → Existing Files..”
  6. Navigate into the “/Classes/” directory and select “SHPolygon.h” and “SHPolygon.m”, then click “add”
  7. On the next window, leave all options as default and click “add”
  8. In the “Groups & Files” pane, Open “Sparrow.h”
    • Example “Sparrow → Classes → Sparrow.h”
  9. At the bottom of the file, add:
    #import "SHPolygon.h"
  10. Save “Sparrow.h”
  11. Close “Sparrow.xcodeproj”

Source Code

Changelog

  • 2011-02-06: First version
  • 2011-03-19: Fixed small bug

Todo

  • Add anti-aliasing
  • Use Core Graphics instead of OpenGL ES
  • Only capture touch inside the polygon
  users/shilo/extensions/shpolygon.txt · Last modified: 2013/08/30 15:50 by shilo
 
Powered by DokuWiki