SHCircle

type:
extension
author:
Shilo White
description:
A simple customizable circle.
lastupdate:
2011-03-14
compatible:
v1.X
tag:
circle, primitive
homepage:
https://gist.github.com/870359
download:
https://gist.github.com/gists/870359/download
sample:
http://shilo.coarsemode.com/sparrow/extensions/shcircle/PacmanSample.zip

Description

SHCircle class will allow you to create primitive circles on the stage. You can 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, set the degrees to render, rotate around center, and everything else you can do with an SPDisplayObject.

Sample

Example

//initialize a circle with width of 100 and height of 100
SHCircle *circle = [SHCircle circleWithWidth:100 height:100];
 
//set the x radius to 25, which changes the width to 50
circle.radiusX = 25.0f;
 
//set the y radius to 10, which changes the height to 20
circle.radiusY = 10.0f;
 
//render half of the circle
circle.degrees = 180;
 
//rotate the circle 45 degrees around the center
circle.centerRotation = 45;
 
//change the solid color to blue
circle.color = 0x0000ff;
 
//change the inner color to red and outer color to black
circle.innerColor = 0xff0000;
circle.outerColor = 0x000000;
 
//toggle the border on
circle.border = YES;
 
//set the border width to 1 pixel
circle.borderWidth = 1.0f;
 
//set the border color to red
circle.borderColor = 0xff0000;
 
//toggle the fill off
circle.fill = NO;
 
//center the circle on stage
circle.centerX = 320/2;
circle.centerY = 480/2;
 
//add the circle to stage
[self addChild:circle];

Instructions

To add into your Sparrow project

  1. Download the source files here: https://gist.github.com/gists/870359/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 "SHCircle.h"
  6. Save “Game.h”

To add directly into Sparrow source

  1. Download the source files here: https://gist.github.com/gists/870359/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 “SHCircle.h” and “SHCircle.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 "SHCircle.h"
  10. Save “Sparrow.h”
  11. Close “Sparrow.xcodeproj”

Source Code

Changelog

  • 2011-01-27: First version

Todo

  • Add anti-aliasing
  • Use Core Graphics instead of OpenGL ES
  • Only capture touch inside the circle
  users/shilo/extensions/shcircle.txt · Last modified: 2013/03/05 10:19 by 127.0.0.1
 
Powered by DokuWiki