jStage.Polygon

Description

The base class of all jStage world objects, a Polygon consists of a set of linked vertices (represented using jStage.Vector), as well as some very rudimentary rendering controls.

Hierarchy

Function List

Function Documentation

Polygon(points, base)constructor

Parameters

points:Pass an array of local-space vectors (with >= 3 elements) to build a closed Poly upon creation, or null to explicitly build it using jStage.Polygon.polyAdd later.

base:Another polygon upon which to 'base' this one (in the scene graph), or null to leave this poly baseless.

addLocation(x, y)

Adds to the location of this Polygon in local space.

Parameters

x:The amount to add to the X value of the local space location.

y:The amount to add to the Y value of the local space location.

Returns

this (itself) - so you can chain operations.

addRotation(rotation)

Adds to the local rotation of this Polygon.

Parameters

rotation:The amount to add to the local space rotation, in radians.

Returns

this (itself) - so you can chain operations.

getAlpha()

Gets the multiplied alpha value of this Polygon, based on it's own _alpha property and that of it's parent nodes on the scene graph.

Returns

A floating point value between 0.0 and 1.0 (inclusive) representing the multiplied alpha value of this Polygon.

Remarks

The return value is multiplicative; if this Polygon has alpha == 0.5 and it's parent has alpha == 0.5, the actual returned value will be 0.25.

getLocation()

Gets the location of this Polygon in world space.

Returns

A reference to the jStage.Vector object containing this Polygon's location.

Remarks

Do not modify the values directly, as they will not propagate to child vertices and polygons. Use setLocation(x, y) for this purpose instead.

getVisible()

Gets the visiblity of this Polygon, based on it's own _visible property and that of it's parent nodes on the scene graph.

Returns

A boolean value representing the actual visibility state of this Polygon.

Remarks

Even if this Polygon has _visible == true, this function will return false if any parents have it set to false.

invalidate()

Explicitly invalidates the root of the scene graph containing this Polygon, forcing a repaint on the next animation frame.

Returns

this (itself) - so you can chain operations.

Remarks

If this Polygon is currently invisible (as per isCurrentlyVisible()), then this function has no effect.

isCurrentlyVisible()

Determines if this Polygon (and it's children) is currently visible on the scene graph based on the return values of getVisible() and getAlpha().

Returns

True if this Polygon is currently visible and has an alpha value greater than 0.0, false otherwise.

polyBase(poly)

Sets the 'base' of this Polygon.

Parameters

poly:The polygon to use as the new base. Pass null for no base.

Returns

this (itself) - so you can chain operations.

Remarks

You cannot use an unenclosed (incomplete) poly as a base. Attempting to do so will have no effect.

setLocation(x, y)

Sets the location of this Polygon in local space.

Parameters

x:The new X value of the local space location.

y:The new Y value of the local space location.

Returns

this (itself) - so you can chain operations.

setRotation(rotation)

Sets the local rotation of this Polygon.

Parameters

rotation:The new value for the local space rotation, in radians.

Returns

this (itself) - so you can chain operations.

setRotationDeg(rotation)

Sets the local rotation of this Polygon.

Parameters

rotation:The new value for the local space rotation, in degrees.

Returns

this (itself) - so you can chain operations.

setTransform(x, y, rotation)

Combines the actions of setLocation(x, y) and setRotation(rotation) for a more convenient (and faster) call.

Parameters

x:The new X value of the local space location.

y:The new Y value of the local space location.

rotation:The new value for the local space rotation, in radians.

Returns

this (itself) - so you can chain operations.

setVisible(vis)

Sets the visibility of this Polygon.

Parameters

vis:A boolean value representing the visibility of this Polygon.

Returns

this (itself) - so you can chain operations.

Remarks

you do not need to call invalidate(), it is done for you.

toString()

Gets a string summary of this Polygon's world vertices, presented in a human-readable format.

Returns

A string containing a list of all world vertices.