Skip to content

When Starling's Quad isn't enough, this extension comes to rescue

Notifications You must be signed in to change notification settings

Fovea/starling-shapes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

Starling Shapes

(c)2014, Fovea

This extension was developed for the game Shyring. See it in action!

Why?

Why another extension, when there's already the Starling Graphics Extension?

The original functionality of these classes was to avoid the draw-back of the Graphics extension not allowing you to flatten your sprites. Which resulted in poor performances, especially if you have complex static objects that could have been pre-rendered.

In Starling 2 flatten has been removed. Starling developers have noted the flatten feature might come back in the future.

If all you need are Lines, Circles and custom Polygons, then do not look any further.

Shapes

starling.display.Poly4

A Poly4 represents an abitrary 4-sided polygon with a uniform color or a color gradient.

Poly4(p1:Point, p2:Point, p3:Point, p4:Point, color:uint=0xffffff)

It inherits directly from starling.display.Quad, so all fancy coloring options of Quads can be used with Poly4.

Hit test: the polygon's axis-aligned bounding box.

starling.display.Ring

A Ring represents a ring (what else?), see this image.

constructor:

Ring(innerRadius:Number, outerRadius:Number, color:uint=0xffffff)

It's built using a set of polygons. Number of vertices is relative to the outer radius.

Hit test: fully functional.

starling.display.Disk

A Disk is like a ring but without a hole in the middle.

constructor:

Disk(radius:Number, color:uint=0xffffff)

It's actually a ring with innerRadius set to 0.

Hit test: fully functional.

starling.display.Line

A Line represents a segment with a thickness and uniform color or a color gradient.

constructor:

Line(from:Point, to:Point, thickness:Number, color:uint)

It inherit from the Poly4 class which means you can setup per-vertex color. The first two points of the Poly4 are those associated with the from point of the Line. The last two points are associated with the to point of the Line.

Hit test: the line's axis-aligned bounding box.

Hit tests?

Used for example to know if the mouse clicked on the object or not. Bounding box hit tests only check if the coordinate falls inside the axis-aligned rectangle that covers the object.

If you don't need pixel-perfect hit tests for the Shape you're drawing (or maybe no hit-test at all), then don't worry.

About

When Starling's Quad isn't enough, this extension comes to rescue

Resources

Stars

Watchers

Forks

Packages

No packages published