PDG engine v0.9.5
 All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | Related Functions | List of all members
SpriteLayer Class Reference

creates and tracks collections of sprites More...

Inheritance diagram for SpriteLayer:
Inheritance graph
[legend]
Collaboration diagram for SpriteLayer:
Collaboration graph
[legend]

Public Member Functions

 addSprite (Sprite newSprite)
 add an existing sprite to the layer
 
Sprite createSprite ()
 create a sprite that belongs to this layer
 
Sprite createSpriteFromSCML (string inSCML, string inEntityName=null)
 create a single sprite from SCML data
 
Sprite createSpriteFromSCMLEntity (string inEntityName)
 create a sprite from SCML data that was previously loaded
 
Sprite createSpriteFromSCMLFile (string inFileName, string inEntityName=null)
 create a sprite from an SCML data file
 
 deserialize (Deserializer deserializer)
 deserialize a sprite layer
 
 disableCollisions ()
 stop checking for collisions between objects in this layer
 
 disableCollisionsWithLayer (SpriteLayer otherLayer)
 remove layer from list of layers that do collisions between layers
 
 enableCollisions ()
 allow collision checking for sprites in this layer
 
 enableCollisionsWithLayer (SpriteLayer otherLayer)
 start collision checking with sprites in another layer
 
 fadeIn (int msDuration, int easing=linearTween)
 fade entire layer to full opacity over time
 
 fadeOut (int msDuration, int easing=linearTween)
 fade out the entire layer to full transparency over time
 
Sprite findSprite (int id)
 find a sprite in this layer by user assigned id
 
number getMyClassTag ()
 returns class tag for SpriteLayer, used for serialization
 
Sprite getNthSprite (int index)
 get a sprite by z-order
 
Point getOrigin ()
 get the point in the layer that is drawn at 0,0 in the port
 
uint getSerializedSize (Serializer serializer)
 get the bytes needed to serialize the layer
 
CpSpace getSpace ()
 get the Chipmunk Physics CpSpace for the layer
 
Port getSpritePort ()
 get the Port the layer renders into
 
int getSpriteZOrder (Sprite sprite)
 get the z-order of a sprite in this layer
 
number getZoom ()
 get the current zoom factor
 
int getZOrder ()
 get the z-order of this layer compared to all others
 
boolean hasSprite (Sprite sprite)
 see if a particular sprite belongs to this layer
 
 hide ()
 stop rendering this layer.
 
boolean isHidden ()
 true if layer is hidden, false if it is visible
 
boolean isSpriteBehind (Sprite sprite, Sprite otherSprite)
 returns true if sprite will be drawn before otherSprite
 
Offset layerToPortOffset (Offset o)
 adjust the offset to account for layer transformations
 
Point layerToPortPoint (Point p)
 translate the point to account for layer transformations
 
Quad layerToPortQuad (Quad q)
 translate the Quad to account for layer transformations
 
RotatedRect layerToPortRect (Rect r)
 translate the rectangle (or RotatedRect) to account for layer transformations
 
Vector layerToPortVector (Vector v)
 translate the point to account for layer transformations
 
 moveBehind (SpriteLayer layer)
 change the z-order of this layer to draw it before the given layer
 
 moveInFrontOf (SpriteLayer layer)
 change the z-order of this layer to draw it after the given layer
 
 moveToBack ()
 move this layer behind all other layers
 
 moveToFront ()
 move this layer in front of all other layers
 
 moveWith (SpriteLayer layer, number moveRatio=1.0, number zoomRatio=1.0)
 link this layer to follow another layer's movements
 
IEventHandler on (int eventCode, function func)
 set event handler for all different sprite and spritelayer events
 
IEventHandler onAnimationComplete (function func)
 set event handler for layer animation complete events
 
IEventHandler onAnimationEnd (function func)
 set event handler for sprite animation end events
 
IEventHandler onAnimationLoop (function func)
 set event handler for sprite animation loop events
 
IEventHandler onAnimationStart (function func)
 set event handler for layer animation complete events
 
IEventHandler onCollideSprite (function func)
 set event handler for sprite-to-sprite collision events
 
IEventHandler onCollideWall (function func)
 set event handler for sprite-wall collision events
 
IEventHandler onDrawPortComplete (function func)
 set event handler for rendering complete events
 
IEventHandler onErasePort (function func)
 set event handler for rendering starting events
 
IEventHandler onExitLayer (function func)
 set event handler for sprite out of bounds event
 
IEventHandler onFadeComplete (function func)
 set event handler for sprite fade event
 
IEventHandler onFadeInComplete (function func)
 set event handler for sprite fade in event
 
IEventHandler onFadeOutComplete (function func)
 set event handler for sprite fade out event
 
IEventHandler onLayerFadeInComplete (function func)
 set event handler for layer fade in event
 
IEventHandler onLayerFadeOutComplete (function func)
 set event handler for layer fade out event
 
IEventHandler onMouseClick (function func)
 set event handler for tap or mouse click in a sprite
 
IEventHandler onMouseDown (function func)
 set event handler for finger down or mouse down in a sprite
 
IEventHandler onMouseEnter (function func)
 set event handler for mouse pointer over a sprite
 
IEventHandler onMouseLeave (function func)
 set event handler for mouse pointer leaving a sprite it was over
 
IEventHandler onMouseUp (function func)
 set event handler for finger up or mouse up in a sprite
 
IEventHandler onOffscreen (function func)
 set event handler for sprite offscreen event
 
IEventHandler onOnscreen (function func)
 set event handler for sprite onscreen event
 
IEventHandler onPostAnimateLayer (function func)
 set event handler for layer animation finished events
 
IEventHandler onPostDrawLayer (function func)
 set event handler for layer rendering complete events
 
IEventHandler onPreAnimateLayer (function func)
 set event handler for layer animation start events
 
IEventHandler onPreDrawLayer (function func)
 set event handler for layer rendering start events
 
IEventHandler onZoomComplete (function func)
 set event handler for this layer finishing zoom animation
 
Offset portToLayerOffset (Offset o)
 adjust the offset to account for layer transformations
 
Point portToLayerPoint (Point p)
 adjust the point to account for layer transformations
 
Quad portToLayerQuad (Quad q)
 adjust the quad to account for layer transformations
 
RotatedRect portToLayerRect (Rect r)
 adjust the rectangle to account for layer transformations
 
Vector portToLayerVector (Vector v)
 adjust the vector to account for layer transformations
 
 removeAllSprites ()
 remove all sprites in the layer
 
 removeSprite (Sprite oldSprite)
 remove a particular sprite from the layer
 
 serialize (Serializer serializer)
 serialize the sprite layer and all the sprites in it
 
 setAutoCenter (boolean autoCenter=true)
 keep the center of the layer at the center of the port
 
 setDamping (number damping)
 set the overall resistance to motion over time (Chipmunk Physics Only)
 
 setFixedMoveAxis (boolean fixedAxis=true)
 make movement of the layer relative to the port axis
 
 setGravity (number gravity, boolean keepItDownward=true)
 set the force of gravity pulling everything downward (Chipmunk Physics Only)
 
 setKeepGravityDownward (boolean keepItDownward=true)
 keep gravity relative to the port when the layer is rotated (Chipmunk Physics Only)
 
 setOrigin (Point origin)
 set the point in the layer that is drawn at 0,0 in the port
 
SpriteLayer setSerializationFlags (uint flags)
 set the mode for sprite layer serialization
 
 setSpritePort (Port port)
 set the port this layer is rendered into
 
 setStaticLayer (boolean isStatic=true)
 make objects in this layer not subject to physics forces (Chipmunk Physics Only)
 
 setUseChipmunkPhysics (boolean useIt=true)
 enable or disable use of Chipmunk Physics for a particular layer
 
 setZoom (number zoomLevel)
 immediately set the zoom level for this layer
 
 show ()
 start rendering this layer if it was previously hidden
 
 startAnimations ()
 restart doing animation calculations for this layer if they were stopped
 
 stopAnimations ()
 stop doing animation calculations for this layer
 
 zoom (number deltaZoomLevel, int msDuration, int easing=easeInOutQuad, Rect keepInRect=Rect(0, 0), Point centerOn=Point(0, 0))
 animated zoom by a particular factor over time
 
 zoomTo (number zoomLevel, int msDuration, int easing=easeInOutQuad, Rect keepInRect=Rect(0, 0), Point centerOn=Point(0, 0))
 animated zoom to a particular zoom level over time
 
- Public Member Functions inherited from Animated
 accelerate (number deltaSpeed, int msDuration=duration_Instantaneous, int easing=linearTween)
 change the object's speed over time
 
 accelerateTo (number speed, int msDuration=duration_Instantaneous, int easing=linearTween)
 change the object's speed to a particular value over time
 
 addAnimationHelper (IAnimationHelper helper)
 setup a helper to handle custom animation
 
boolean animate (int msElapsed)
 animate based on the passage of time
 
 applyForce (Vector force, int msDuration=duration_Instantaneous)
 apply a force to the object over time
 
 applyTorque (number forceSpin, int msDuration=duration_Instantaneous)
 apply torque to the object over time
 
 changeCenter (Offset offset, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 shift the center point of the object over time
 
 changeCenterTo (Offset offset, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 shift the center point of the object to a particular offset from true center over time
 
 clearAnimationHelpers ()
 remove all previously added animation helpers
 
Rect getBoundingBox ()
 get the rectangle that completely encloses the object
 
Offset getCenterOffset ()
 get the current offset of the center relative to the true center point
 
number getHeight ()
 get height of the object
 
Point getLocation ()
 get the position of the object
 
number getMass ()
 get the mass of the object
 
number getMoveFriction ()
 get the amount of friction for movement
 
number getMovementDirectionInRadians ()
 get the direction the object is moving
 
RotatedRect getRotatedBounds ()
 get the bounds with rotation
 
number getRotation ()
 get how much the object is rotated
 
number getSizeFriction ()
 get the friction applied to size changes (growing or shrinking)
 
number getSpeed ()
 get how fast the object is moving in pixels/sec
 
number getSpin ()
 get how fast the object is spinning in radians per second
 
number getSpinFriction ()
 get the friction applied toward spinning
 
Vector getVelocity ()
 get the vector that expresses magnitude and direction of the object's movement in pixels/sec
 
number getWidth ()
 get the width of the object
 
 grow (number factor, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 change size of the object by a factor over time
 
 move (Offset delta, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 move the object by a certain amount over time
 
 moveTo (Point where, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 move the object to a particular location over time
 
 removeAnimationHelper (IAnimationHelper helper)
 remove a specific animation helper
 
 resize (number deltaWidth, number deltaHeight, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 change the size of an object by a given amount over time
 
 resizeTo (number width, number height, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 resize the object to a specific size over time
 
 rotate (number radians, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 rotate the object by a specific amount over time
 
 rotateTo (number radiansRotation, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 rotate the object to face a particular direction over time
 
Animated setCenterOffset (Offset inCenterOffset)
 set the offset of the center point relative to the true center
 
Animated setFriction (number frictionCoefficient)
 set friction for movement, rotation and resizing all at once
 
Animated setHeight (number inHeight)
 set the object's height
 
Animated setLocation (Point inLocation)
 place the object at a particular location
 
Animated setMass (number inMass)
 set the object's mass, used when forces are applied
 
Animated setMoveFriction (number inMoveFriction)
 set the object's friction for movement
 
Animated setRotation (number inRotation)
 set the direction the object is facing in radians
 
Animated setSize (number width, number height)
 set the size of the object
 
Animated setSizeFriction (number inSizeFriction)
 set the friction applied for object resizing
 
Animated setSpeed (number inSpeed)
 set the speed the object is moving in its current direction of motion
 
Animated setSpin (number inSpin)
 set the rate at which the object is spinning, in radians/sec
 
Animated setSpinFriction (number inSpinFriction)
 set the friction the object faces for spinning
 
Animated setVelocity (Vector deltaPerSec)
 set the speed and direction the object is moving
 
Animated setVelocity (number deltaXPerSec, number deltaYPerSec)
 set the speed and direction the object is moving
 
Animated setVelocityInRadians (number speed, number direction)
 set the speed and direction the object is moving
 
Animated setWidth (number inWidth)
 set the width of the object
 
 startGrowing (number amountPerSecond)
 set the growth rate of the object in pixels/sec
 
 startStretching (number widthPerSecond, number heightPerSecond)
 set the growth rate of the object in pixels/sec, with varied rates for width and height
 
 stopAllForces ()
 remove all forces that were acting on the object (except friction)
 
 stopGrowing ()
 stop any size change
 
 stopMoving ()
 stop any movement the object was doing (except spinning)
 
 stopSpinning ()
 stop any spinning the object was doing
 
 stopStretching ()
 stop any stretching the object was doing
 
 stretch (number widthFactor, number heightFactor, int msDuration=duration_Instantaneous, int easing=easeInOutQuad)
 change the dimensions of the object over time
 
Animated wait (int msDuration)
 wait before beginning the next animation call that operates over time
 
- Public Member Functions inherited from EventEmitter
 addHandler (IEventHandler inHandler, int inEventType=all_events)
 add a new handler for some event type, or for all events if no type specified.
 
 blockEvent (int inEventType)
 temporarily ignore all events of a particular type.
 
 clear ()
 remove all handlers
 
 removeHandler (IEventHandler inHandler, int inEventType=all_events)
 remove a handler for some event type, or for all events (see note) if no type specified.
 
 unblockEvent (int inEventType)
 stop ignoring events of a particular type
 

Related Functions

(Note that these are not member functions.)

 cleanupSpriteLayer
 free all the memory used by a SpriteLayer
 
 createSpriteLayer
 create a new SpriteLayer attached to a particular port
 
 createSpriteLayerFromSCMLFile
 create a new SpriteLayer from an Spriter SCML file
 

Detailed Description

creates and tracks collections of sprites

Note
API Stability: 2 - Unstable. The API is in the process of settling, but has not yet had sufficient real-world testing to be considered stable. Backwards-compatibility will be maintained if reasonable.

Events

Things that happen to a sprite that might require intervention, such as collisions, completed animations, going offscreen, etc... will generate events. Events generated by sprites first go to any handlers attached directly to the Sprite, then propagate up to the SpriteLayer and then the EventManager until they are handled.

Things that happen to a sprite layer go to the layer's handlers first, then propagate to the EventManager's handlers if they weren't handled by the layer.

Member Function Documentation

addSprite ( Sprite  newSprite)

add an existing sprite to the layer

Warning
if the sprite already belongs to another layer this call is ignored
createSprite ( )

create a sprite that belongs to this layer

createSpriteFromSCML ( string  inSCML,
string  inEntityName = null 
)

create a single sprite from SCML data

createSpriteFromSCMLEntity ( string  inEntityName)

create a sprite from SCML data that was previously loaded

createSpriteLayerFromSCMLFile() and createSpriteFromSCMLFile() both cache their file data for this purpose

createSpriteFromSCMLFile ( string  inFileName,
string  inEntityName = null 
)

create a sprite from an SCML data file

deserialize ( Deserializer  deserializer)

deserialize a sprite layer

disableCollisions ( )

stop checking for collisions between objects in this layer

disableCollisionsWithLayer ( SpriteLayer  otherLayer)

remove layer from list of layers that do collisions between layers

Note
Layers that have Chipmunk Physics enabled handle layer-to-layer collisions differently, they collide automatically even between layers unless you put them in collide groups.
See Also
enableCollisionsWithLayer
Sprite.setCollideGroup()
Sprite.enableCollisions()
Sprite.setCollisionHelper()
enableCollisions ( )

allow collision checking for sprites in this layer

enableCollisionsWithLayer ( SpriteLayer  otherLayer)

start collision checking with sprites in another layer

Note
Layers that have Chipmunk Physics enabled handle layer-to-layer collisions differently, they collide automatically even between layers unless you put them in collide groups.
See Also
disableCollisionsWithLayer
fadeIn ( int  msDuration,
int  easing = linearTween 
)

fade entire layer to full opacity over time

Generates an eventType_SpriteLayer action_LayerFadeInComplete event when done.

Warning
does not honor delay specified by wait()
fadeOut ( int  msDuration,
int  easing = linearTween 
)

fade out the entire layer to full transparency over time

Generates an eventType_SpriteLayer action_LayerFadeOutComplete event when done.

Warning
does not honor delay specified by wait()
findSprite ( int  id)

find a sprite in this layer by user assigned id

getMyClassTag ( )

returns class tag for SpriteLayer, used for serialization

getNthSprite ( int  index)

get a sprite by z-order

index 0 is furthest back

getOrigin ( )

get the point in the layer that is drawn at 0,0 in the port

getSerializedSize ( Serializer  serializer)

get the bytes needed to serialize the layer

Takes into account the serialization mode for this layer

See Also
SpriteLayer.setSerializationFlags()
getSpace ( )

get the Chipmunk Physics CpSpace for the layer

Layers generally share the same Chipmunk space so the sprites within them can collide

See Also
CpSpace
getSpritePort ( )

get the Port the layer renders into

getSpriteZOrder ( Sprite  sprite)

get the z-order of a sprite in this layer

0 means furthest back (drawn first)

See Also
getNthSprite
getZoom ( )

get the current zoom factor

getZOrder ( )

get the z-order of this layer compared to all others

0 means furthest back (drawn first)

hasSprite ( Sprite  sprite)

see if a particular sprite belongs to this layer

hide ( )

stop rendering this layer.

Layer continues doing animation calculations and generating events from animation.

isHidden ( )

true if layer is hidden, false if it is visible

isSpriteBehind ( Sprite  sprite,
Sprite  otherSprite 
)

returns true if sprite will be drawn before otherSprite

layerToPortOffset ( Offset  o)

adjust the offset to account for layer transformations

Since an offset is relative rather than fixed in coordinate space, this means only rotating it around 0,0 to match the layer rotation, and changing the offset length by the layer zoom. The layer origin is not factored in.

Parameters
oOffset in layer coordinates
Returns
Offset in port coordinates
layerToPortPoint ( Point  p)

translate the point to account for layer transformations

Adjusts for layer rotation, zoom and scrolling (origin) to get drawing coordinates.

Parameters
pPoint in layer coordinates
Returns
Point in port coordinates
layerToPortQuad ( Quad  q)

translate the Quad to account for layer transformations

Adjusts for layer rotation, zoom and scrolling (origin) to get drawing coordinates.

Parameters
qQuad in layer coordinates
Returns
Quad in port coordinates
layerToPortRect ( Rect  r)

translate the rectangle (or RotatedRect) to account for layer transformations

Adjusts for layer rotation, zoom and scrolling (origin) to get drawing coordinates.

Parameters
rRect or RotatedRect in layer coordinates
Returns
RotatedRect in port coordinates
layerToPortVector ( Vector  v)

translate the point to account for layer transformations

Adjusts for layer rotation, zoom to get drawing coordinates. As with offset, vectors are not fixed in space, so origin is not considered.

Parameters
vVector in layer coordinates
Returns
Vector in port coordinates
moveBehind ( SpriteLayer  layer)

change the z-order of this layer to draw it before the given layer

moveInFrontOf ( SpriteLayer  layer)

change the z-order of this layer to draw it after the given layer

moveToBack ( )

move this layer behind all other layers

moveToFront ( )

move this layer in front of all other layers

moveWith ( SpriteLayer  layer,
number  moveRatio = 1.0,
number  zoomRatio = 1.0 
)

link this layer to follow another layer's movements

Whenever the given layer is moved, rotated or zoomed, this layer will be transformed in the same way. There is the option for a relative movement and zoom factor, to primarily useful to simulate a crude depth effect. Rotation is always 1:1.

on ( int  eventCode,
function  func 
)

set event handler for all different sprite and spritelayer events

See Also
IEventHandler
onAnimationComplete ( function  func)

set event handler for layer animation complete events

This happens when all sprite layers are done calculating animation changes

See Also
SpriteLayerEvent
IEventHandler
onAnimationEnd ( function  func)

set event handler for sprite animation end events

These happen when a sprite finishes a particular frame animation sequence

See Also
SpriteAnimateEvent
IEventHandler
onAnimationLoop ( function  func)

set event handler for sprite animation loop events

These happen when a sprite finishes a particular frame animation sequence and is restarting it because it is set to loop

See Also
SpriteAnimateEvent
IEventHandler
onAnimationStart ( function  func)

set event handler for layer animation complete events

This happens just before the sprite system starts calculating animation changes for the layers

See Also
SpriteLayerEvent
IEventHandler
onCollideSprite ( function  func)

set event handler for sprite-to-sprite collision events

These happen when a sprite collides with another sprite. Collisions must be enabled for the sprite and the layer.

See Also
SpriteCollideEvent
IEventHandler
onCollideWall ( function  func)

set event handler for sprite-wall collision events

These happen when a sprite collides with the boundaries of the layer, but only if setWantsCollideWallEvents(true) is called for that sprite.

See Also
SpriteCollideEvent
IEventHandler
onDrawPortComplete ( function  func)

set event handler for rendering complete events

This happens each frame when all layers have finished rendering that frame

See Also
SpriteLayerEvent
IEventHandler
onErasePort ( function  func)

set event handler for rendering starting events

This happens each frame before any layers start rendering for that frame

See Also
SpriteLayerEvent
IEventHandler
onExitLayer ( function  func)

set event handler for sprite out of bounds event

These happen when a sprite moves completely outside the boundaries of the layer, but only if setWantsCollideWallEvents(true) is called for that sprite.

See Also
SpriteAnimateEvent
IEventHandler
Sprite.setWantsCollideWallEvents()
onFadeComplete ( function  func)

set event handler for sprite fade event

These happen when a sprite completes a fade over time done by fadeTo()

See Also
SpriteAnimateEvent
IEventHandler
Sprite.fadeTo()
onFadeInComplete ( function  func)

set event handler for sprite fade in event

These happen when a sprite completes a fade in over time done by Sprite.fadeIn()

See Also
SpriteAnimateEvent
IEventHandler
Sprite.fadeIn()
onFadeOutComplete ( function  func)

set event handler for sprite fade out event

These happen when a sprite completes a fade out over time done by Sprite.fadeOut()

See Also
SpriteAnimateEvent
IEventHandler
Sprite.fadeOut()
onLayerFadeInComplete ( function  func)

set event handler for layer fade in event

These happen when this layer completes a fade in over time done by fadeIn()

See Also
fadeIn()
SpriteLayerEvent
IEventHandler
onLayerFadeOutComplete ( function  func)

set event handler for layer fade out event

These happen when this layer completes a fade out over time done by fadeOut()

See Also
fadeOut()
SpriteLayerEvent
IEventHandler
onMouseClick ( function  func)

set event handler for tap or mouse click in a sprite

Only works for Sprites that have setWantsClickEvents(true).

See Also
SpriteTouchEvent
IEventHandler
Sprite.setWantsClickEvents()
onMouseDown ( function  func)

set event handler for finger down or mouse down in a sprite

Only works for Sprites that have setWantsClickEvents(true).

See Also
SpriteTouchEvent
IEventHandler
Sprite.setWantsClickEvents()
onMouseEnter ( function  func)

set event handler for mouse pointer over a sprite

Only works for Sprites that have setWantsMouseOverEvents(true).

See Also
SpriteTouchEvent
IEventHandler
Sprite.setWantsMouseOverEvents()
onMouseLeave ( function  func)

set event handler for mouse pointer leaving a sprite it was over

Only works for Sprites that have setWantsMouseOverEvents(true).

See Also
SpriteTouchEvent
IEventHandler
Sprite.setWantsMouseOverEvents()
onMouseUp ( function  func)

set event handler for finger up or mouse up in a sprite

Only works for Sprites that have setWantsClickEvents(true).

See Also
SpriteTouchEvent
IEventHandler
Sprite.setWantsClickEvents()
onOffscreen ( function  func)

set event handler for sprite offscreen event

These happen when a sprite moves completely outside the visible area of the port the layer is being rendered in, but only if setWantsOffscreenEvents(true) is called for that sprite.

See Also
SpriteAnimateEvent
IEventHandler
Sprite.setWantsOffscreenEvents()
onOnscreen ( function  func)

set event handler for sprite onscreen event

These happen when a sprite moves into the visible area of the port the layer is being rendered into, but only if Sprite.setWantsOffscreenEvents(true) is called for that sprite.

See Also
SpriteAnimateEvent
IEventHandler
Sprite.setWantsOffscreenEvents()
onPostAnimateLayer ( function  func)

set event handler for layer animation finished events

This happens each frame when this particular layer is has finished calculating the changes for the animation step.

See Also
onPreAnimateLayer()
SpriteLayerEvent
IEventHandler
onPostDrawLayer ( function  func)

set event handler for layer rendering complete events

This happens each frame when a this particular layer has finished rendering that frame

See Also
SpriteLayerEvent
IEventHandler
onPreAnimateLayer ( function  func)

set event handler for layer animation start events

This happens each frame when this particular layer is about to start calculating the changes for the animation step.

See Also
SpriteLayerEvent
IEventHandler
onPreDrawLayer ( function  func)

set event handler for layer rendering start events

This happens each frame before this particular layer starts rendering that frame

See Also
SpriteLayerEvent
IEventHandler
onZoomComplete ( function  func)

set event handler for this layer finishing zoom animation

See Also
zoom()
zoomTo()
SpriteLayerEvent
IEventHandler
portToLayerOffset ( Offset  o)

adjust the offset to account for layer transformations

Since an offset is relative rather than fixed in coordinate space, this means only rotating it around 0,0 to match the layer rotation, and changing the offset length by the layer zoom. The layer origin is not factored in.

Parameters
oOffset in port coordinates
Returns
Offset in layer coordinates
portToLayerPoint ( Point  p)

adjust the point to account for layer transformations

Adjusts for layer rotation, zoom and scrolling (origin) to get layer coordinates for a point on the screen.

Parameters
pPoint in port coordinates
Returns
Point in layer coordinates
portToLayerQuad ( Quad  q)

adjust the quad to account for layer transformations

Adjusts for layer rotation, zoom and scrolling (origin) to get layer coordinates for the quad on the screen.

Parameters
qQuad in port coordinates
Returns
Quad in layer coordinates
portToLayerRect ( Rect  r)

adjust the rectangle to account for layer transformations

Adjusts for layer rotation, zoom and scrolling (origin) to get layer coordinates for a rectangle on the screen.

Parameters
rRect in port coordinates
Returns
Rect in layer coordinates
portToLayerVector ( Vector  v)

adjust the vector to account for layer transformations

Since a vector is relative rather than fixed in coordinate space, this means only rotating it around 0,0 to match the layer rotation, and changing the vector length by the layer zoom. The layer origin is not factored in.

Parameters
vVector in port coordinates
Returns
Vector in layer coordinates
removeAllSprites ( )

remove all sprites in the layer

removeSprite ( Sprite  oldSprite)

remove a particular sprite from the layer

serialize ( Serializer  serializer)

serialize the sprite layer and all the sprites in it

Note
uses setting from setSerializationFlags() to determine how to optimize serialization for particular needs
See Also
setSerializationFlags()
setAutoCenter ( boolean  autoCenter = true)

keep the center of the layer at the center of the port

When autoCenter is on, it makes rotations always be around the visible center of the layer, rather than around its mathematical center based on the bounds.

setDamping ( number  damping)

set the overall resistance to motion over time (Chipmunk Physics Only)

setFixedMoveAxis ( boolean  fixedAxis = true)

make movement of the layer relative to the port axis

If setFixedMoveAxis is true, move(10, 0) will move the layer 10 pixels to the right in port coordinates. This gives move natural control over movement when the user can spin and move the layer.

setGravity ( number  gravity,
boolean  keepItDownward = true 
)

set the force of gravity pulling everything downward (Chipmunk Physics Only)

If keepItDownward is true (the default), then direction of gravity will be automatically be adjusted to point downward relative to the port if the layer is rotated.

setKeepGravityDownward ( boolean  keepItDownward = true)

keep gravity relative to the port when the layer is rotated (Chipmunk Physics Only)

setOrigin ( Point  origin)

set the point in the layer that is drawn at 0,0 in the port

setSerializationFlags ( uint  flags)

set the mode for sprite layer serialization

See Also
ser_Micro
ser_Update
ser_Full
setSpritePort ( Port  port)

set the port this layer is rendered into

setStaticLayer ( boolean  isStatic = true)

make objects in this layer not subject to physics forces (Chipmunk Physics Only)

Other objects can still collide with static object, but they are treated as having infinite mass.

Warning
This must be called before you start adding Sprites to the layer
setUseChipmunkPhysics ( boolean  useIt = true)

enable or disable use of Chipmunk Physics for a particular layer

Layers that don't use Chipmunk Physics can still use the cruder physics system offered by the Animated class.

setZoom ( number  zoomLevel)

immediately set the zoom level for this layer

show ( )

start rendering this layer if it was previously hidden

startAnimations ( )

restart doing animation calculations for this layer if they were stopped

stopAnimations ( )

stop doing animation calculations for this layer

Note
this does not stop it from rendering, but all motion in the layer will cease
Warning
Chipmunk Physics based movement will continue if this is a layer using Chipmunk Physics
zoom ( number  deltaZoomLevel,
int  msDuration,
int  easing = easeInOutQuad,
Rect  keepInRect = Rect(0,0),
Point  centerOn = Point(0,0) 
)

animated zoom by a particular factor over time

Generates SpriteLayerEvent with action_ZoomComplete when done

See Also
zoomTo()
SpriteLayerEvent
zoomTo ( number  zoomLevel,
int  msDuration,
int  easing = easeInOutQuad,
Rect  keepInRect = Rect(0,0),
Point  centerOn = Point(0,0) 
)

animated zoom to a particular zoom level over time

Generates SpriteLayerEvent with action_ZoomComplete when done

See Also
zoom()
SpriteLayerEvent

Friends And Related Function Documentation

cleanupSpriteLayer
related

free all the memory used by a SpriteLayer

createSpriteLayer
related

create a new SpriteLayer attached to a particular port

Parameters
portif passed, associate with a specific port, otherwise, associate with the main port
See Also
GraphicsManager.getMainPort()
createSpriteLayerFromSCMLFile
related

create a new SpriteLayer from an Spriter SCML file

Parameters
layerSCMLFilenamethe path and name of the SCML file
addSpritesif true, all entities found in the SCML file will be added as sprites to the layer. If false, the SCML file will be loaded and all it's data will be cached for layer use by SpriteLayer.createSpriteFromSCMLEntity()
portif passed, associate with a specific port, otherwise, associate with the main port
See Also
GraphicsManager.getMainPort()
SpriteLayer.createSpriteFromSCMLEntity()

User Comments