Foundation.ChainSprite
ChainSprites are hierarchal groupings of sprites where each ChainSprite can have 0 or more children which transform with their parent. ChainSprites do not support back-referencing to parent elements, only forward referencing to children. When a ChainSprite is transformed (translated, rotated, scaled), the transformation operation is applied to both it and all of it's children and descendants.
Example
// Create a sprite at 100, 200 which is 300 units wide by 400 units high
var sprite = new Foundation.ChainSprite(
new Foundation.Rectangle(100, 200, 300, 400),
someTexture.getRegion('someRegion')
);
// Add a child just below it
sprite.children.add('foo', new Foundation.ChainSprite(
new Foundation.Rectangle(100, 600, 300, 400),
someTexture.getRegion('otherRegion')
));
// Rotate **both** elements around sprite's origin point
sprite.rotate(Math.PI);
Implementation Details
Reference paths
'/foundation/_digest.ts''/foundation/core/actors/_digest.ts''/foundation/core/actors/ChainSprite.ts'
Extends
This type extends:
The bounds property returns the bounding rectangle of the current item and all of its descendants.
Implements
This type does not implement any interfaces (save those in the base).
Public Properties
children: OrderedUpdateDictionary<ChainSprite>
- An ordered update dictionary of chain sprites which are the children of the current element.
chainAlpha: number
- Set the alpha value for the current item and all descendants (
.alphacan be used to set for current item only). - Alpha clamped to [0,1]
Hierarchal Transformation Instance Methods
The following transformation operations work as they do in the Sprite type, but will also be applied to all descendants of the current chain sprite:
transform(rotate: number, translateX: number, translateY: number, scaleX: number, scaleY: number): ChainSprite
rotate(rads: number): ChainSprite
rotateAround(x: number, y: number, rads: number): ChainSprite
translate(x: number, y: number): ChainSprite
scale(scaleX: number, scaleY: number): ChainSprite
scaleAround(x: number, y: number, scaleX: number, scaleY: number): ChainSprite
The resetGeometry() method will only reset geometry on the current item. The resetChainGeometry() method is provided to reset geometry on the current item and all descendants.