SHLine

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

Description

SHLine class will allow you to create primitive lines on the stage. You can customize both vertex colors and alpha, change the thickness, set the destination to the end of the line, and everything else you can do with an SPDisplayObject, such as rotation.

Sample

Example

//initialize a line with a length of 100 pixels and thickness of 5 pixels
SHLine *line = [SHLine lineWithLength:100 andThickness:5];
 
//set the start color to red
line.startColor = 0xff0000;
 
//set the end color to blue
line.endColor = 0x0000ff;
 
//set the start opacity to 75%
line.startAlpha = 0.75f;
 
//set the end opacity to 25%
line.endAlpha = 0.25f;
 
//set the end destination to the bottom right corner of the screen
line.x2 = 320;
line.y2 = 480;
 
//add the line to the stage
[self addChild:line];
 
//initialize another line with the coords (x, y, width, height)
SHLine *line2 = [SHLine lineWithCoords:0:480:320:-480];
 
//set the line thickness to 5 pixels
line2.thickness = 5;
 
//add line2 to the stage to create a 'cross' pattern
[self addChild:line2];

Instructions

To add into your Sparrow project

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

To add directly into Sparrow source

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

Source Code

Changelog

  • 2011-01-11: First version

Todo

  • Add anti-aliasing
  • Use Core Graphics instead of OpenGL ES
  • Add new initialization methods

Special Thanks

  users/shilo/extensions/shline.txt · Last modified: 2013/03/05 10:19 by 127.0.0.1
 
Powered by DokuWiki