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

Related Functions

(Note that these are not member functions.)

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

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