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

animated, moving image that is automatically moved, animated, and drawn More...

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

Public Member Functions

 addFramesImage (Image image, int startingFrame=start_FromFirstFrame, int numFrames=all_Frames)
 add one or more frames to the sprite from an Image or ImageStrip More...
 
 changeFramesImage (Image oldImage, Image newImage)
 replace all references in the sprite to one image with another image More...
 
 deserialize (Deserializer deserializer)
 update this sprite from the data in stream More...
 
Sprite disableCollisions ()
 stop checking for collisions with this sprite More...
 
 disconnect (Sprite otherSprite=ALL_SPRITES)
 remove all connections (joints) to another sprite More...
 
Sprite enableCollisions (int collisionType=collide_AlphaChannel)
 start checking for collisions with this sprite More...
 
 fadeIn (int msDuration, int easing=linearTween)
 fade in to full opacity over time More...
 
 fadeOut (int msDuration, int easing=linearTween)
 fade out full transparency over time More...
 
 fadeTo (number targetOpacity, int msDuration, int easing=linearTween)
 fade in to a specific opacity over time More...
 
CpConstraint gear (Sprite otherSprite, number gearRatio, number initialAngle=0, number breakingForce=0)
 join two sprites as if they were geared together (Chipmunk Physics Only) More...
 
number getCollideGroup ()
 see which collide group this sprite is part of (Chipmunk Physics Only) More...
 
number getCollisionRadius ()
 get the collision radius for this sprite More...
 
number getCurrentFrame ()
 which frame of animation the sprite is currently showing More...
 
number getElasticity ()
 get the elasticity for this sprite's collisions More...
 
Offset getFrameCenterOffset (Image image=null, int frameNum=0)
 get the offset to the center-point from the true image center for a given frame More...
 
number getFrameCount ()
 get number of frames of animation for this sprite More...
 
RotatedRect getFrameRotatedBounds (int frameNum=-1)
 get the bounds of the sprite, including rotation, for a given frame, in layer coordinates. If no frameNum is passed in, or the frame is not present, the bounds of the current frame are returned. More...
 
number getFriction ()
 get the friction used for movement calculations for this sprite (Chipmunk Physics Only) More...
 
SpriteLayer getLayer ()
 get the layer that contains this sprite More...
 
number getMouseDetectMode ()
 
number getMyClassTag ()
 returns class tag for Sprite, used for serialization More...
 
number getOpacity ()
 get the level of opacity for this sprite More...
 
uint getSerializedSize (Serializer serializer)
 get the bytes needed to serialize the layer More...
 
boolean getWantsAnimEndEvents ()
 
boolean getWantsAnimLoopEvents ()
 
boolean getWantsClickEvents ()
 
boolean getWantsCollideWallEvents ()
 
boolean getWantsMouseOverEvents ()
 
boolean getWantsOffscreenEvents ()
 
int getZOrder ()
 get the z-order of this sprite in the layer it belongs to More...
 
CpConstraint grooveJoint (Offset grooveStart, Offset grooveEnd, Sprite otherSprite, Offset otherAnchor, number breakingForce=0)
 join groove on this sprite to an anchor point on another (Chipmunk Physics Only) More...
 
boolean hasAnimation (int animationId)
 check if a sprite has a particular SCML animation by ID More...
 
boolean hasAnimation (string animationName)
 check if a sprite has a particular SCML animation by name More...
 
boolean isBehind (Sprite sprite)
 returns true if this sprite will be drawn before the given sprite More...
 
 makeJointBreakable (CpConstraint joint, number breakingForce)
 set or change force at which the joint between sprites will break (Chipmunk Physics Only) More...
 
 makeJointUnbreakable (CpConstraint joint)
 make the joint impossible to break (Chipmunk Physics Only) More...
 
Sprite makeStatic ()
 make this sprite unaffected by physics (Chipmunk Physics Only) More...
 
CpConstraint motor (Sprite otherSprite, number spin, number maxTorque=INFINITY)
 keep spin of another sprite at a constant rate compared to this one (Chipmunk Physics Only) More...
 
Sprite moveBehind (Sprite sprite)
 make this sprite be drawn before another sprite (visually behind) More...
 
Sprite moveInFrontOf (Sprite sprite)
 make this sprite be drawn just after another sprite (visually in front of) More...
 
Sprite moveToBack ()
 put this sprite behind all others in its layer More...
 
Sprite moveToFront ()
 put this sprite in front of all others in its layer More...
 
 offsetFrameCenters (int offsetX, int offsetY, Image image=null, int startingFrame=start_FromFirstFrame, int numFrames=all_Frames)
 change the center of rotation for the sprite More...
 
IEventHandler on (int eventCode, function func)
 set event handler for all different sprite 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 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 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 onMouseClick (function func)
 set event handler for tap or mouse click in this sprite More...
 
IEventHandler onMouseDown (function func)
 set event handler for finger down or mouse down in this sprite More...
 
IEventHandler onMouseEnter (function func)
 set event handler for mouse pointer entering this sprite (NOT IMPLEMENTED) More...
 
IEventHandler onMouseLeave (function func)
 set event handler for mouse pointer leaving this sprite (NOT IMPLEMENTED) More...
 
IEventHandler onMouseUp (function func)
 set event handler for finger up or mouse up in this 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...
 
CpConstraint pinJoint (Offset anchor, Sprite otherSprite, Offset otherAnchor, number breakingForce=0)
 pin sprites together at a particular anchor point (offset from center) on each (Chipmunk Physics Only) More...
 
CpConstraint pivotJoint (Sprite otherSprite, Point pivot, number breakingForce=0)
 join sprites together at a particular location in layer coordinates (Chipmunk Physics Only) More...
 
CpConstraint ratchet (Sprite otherSprite, number rachetInterval, number phase, number breakingForce=0)
 join two sprites rotation with a ratchet mechanism (Chipmunk Physics Only) More...
 
 removeJoint (CpConstraint joint)
 remove a joint between two sprites (Chipmunk Physics Only) More...
 
CpConstraint rotaryLimit (Sprite otherSprite, number minAngle, number maxAngle, number breakingForce=0)
 limit the angle another sprite can have relative to this one (Chipmunk Physics Only) More...
 
CpConstraint rotarySpring (Sprite otherSprite, number restAngle, number stiffness, number damping, number breakingForce=0)
 keep sprites at a particular angle relative to one another via a rotary spring (Chipmunk Physics Only) More...
 
 serialize (Serializer serializer)
 serialize this sprite into a data stream More...
 
Sprite setCollideGroup (int group)
 set the collide group this sprite is part of (Chipmunk Physics Only) More...
 
 setCollisionHelper (ISpriteCollideHelper helper)
 set a helper to filter out some collisions for this sprite More...
 
Sprite setCollisionRadius (number pixelRadius)
 set the radius of the collision boundary circle of the sprite More...
 
 setDrawHelper (ISpriteDrawHelper helper)
 set a pre-draw helper for custom sprite drawing More...
 
Sprite setElasticity (number elasticity)
 
Sprite setEntityScale (number xScale, number yScale)
 
Sprite setFrame (int frame)
 
Sprite setMouseDetectMode (int collisionType=collide_BoundingBox)
 
Sprite setOpacity (number opacity)
 
 setPostDrawHelper (ISpriteDrawHelper helper)
 
Sprite setWantsAnimEndEvents (boolean wantsThem=true)
 
Sprite setWantsAnimLoopEvents (boolean wantsThem=true)
 
Sprite setWantsClickEvents (boolean wantsThem=true)
 
Sprite setWantsCollideWallEvents (boolean wantsThem=true)
 
Sprite setWantsMouseOverEvents (boolean wantsThem=true)
 
Sprite setWantsOffscreenEvents (boolean wantsThem=true)
 
CpConstraint slideJoint (Offset anchor, Sprite otherSprite, Offset otherAnchor, number minDist, number maxDist, number breakingForce=0)
 join sprites together via a slider between anchor points that has a min/max distance (Chipmunk Physics Only) More...
 
CpConstraint springJoint (Offset anchor, Sprite otherSprite, Offset otherAnchor, number restLength, number stiffness, number damping, number breakingForce=0)
 join sprites together via a spring between anchor points (Chipmunk Physics Only) More...
 
 startAnimation (int animationId)
 
 startAnimation (string animationName)
 
 startFrameAnimation (number fps, int startingFrame=start_FromFirstFrame, int numFrames=all_Frames, int animateFlags=animate_Looping)
 
 stopFrameAnimation ()
 
 useCollisionMask (Image frameImage, Image maskImage)
 
- 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...
 

Additional Inherited Members

Detailed Description

animated, moving image that is automatically moved, animated, and drawn

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.

Warning
translating events to JavaScript and running them through numerous handlers is expensive. Try to put your handlers as early in the propagation chain as possible.

Helpers

You can add helper functions or classes to do specialized animation behavior, prefilter collisions, and add visual effects during drawing.

See Also
setAnimationHelper()
setDrawHelper()
setPostDrawHelper()
setCollisionHelper()

Member Function Documentation

addFramesImage ( Image  image,
int  startingFrame = start_FromFirstFrame,
int  numFrames = all_Frames 
)

add one or more frames to the sprite from an Image or ImageStrip

changeFramesImage ( Image  oldImage,
Image  newImage 
)

replace all references in the sprite to one image with another image

deserialize ( Deserializer  deserializer)

update this sprite from the data in stream

disableCollisions ( )

stop checking for collisions with this sprite

disconnect ( Sprite  otherSprite = ALL_SPRITES)

remove all connections (joints) to another sprite

If otherSprite is not passed in, it will remove all joints for this sprite, regardless of what sprite they are connected to.

enableCollisions ( int  collisionType = collide_AlphaChannel)

start checking for collisions with this sprite

Collision Types are:

  • collide_None – actually calls disableCollisions()
  • collide_Point – just collide with the centerpoint of the sprite. Very fast.
  • collide_BoundingBox – collide with the boundaries of the sprite (rotated if necessary). Reasonably fast.
  • collide_CollisionRadius – collide with all points within a given radius of the sprite (best guess at radius based on sprite height and width is used unless setCollisionRadius() is called. Very fast.
  • collide_AlphaChannel – per-pixel collision based on the alpha channel of the sprite's current frame. This is the most accurate, but also the slowest. Avoid it if another collision check gives acceptable results, especially with fast-moving items where the difference between a hit and near miss is not obviously visible to the player.
Warning
you must have called Image.retainAlpha() on the sprite's image(s) in order to use collide_AlphaChannel
fadeIn ( int  msDuration,
int  easing = linearTween 
)

fade in to full opacity over time

Generates an eventType_SpriteAnimate action_FadeInComplete event when done.

Note
if a previous call was made to wait() the fade animation will not start until the wait is complete
mySprite.fadeIn(1000);   // immediately start to fade in over the next second
myOtherSprite.wait(2000).fadeIn(1000);  // wait 2 seconds, then fade in
See Also
SpriteAnimateEvent
fadeOut()
fadeTo()
wait()
fadeOut ( int  msDuration,
int  easing = linearTween 
)

fade out full transparency over time

Generates an eventType_SpriteAnimate action_FadeOutComplete event when done.

Note
if a previous call was made to wait() the fade animation will not start until the wait is complete
mySprite.fadeOut(1000);   // immediately start to fade out over the next second
myOtherSprite.wait(2000).fadeOut(1000);  // wait 2 seconds, then fade out
See Also
SpriteAnimateEvent
fadeIn()
fadeTo()
wait()
fadeTo ( number  targetOpacity,
int  msDuration,
int  easing = linearTween 
)

fade in to a specific opacity over time

Generates an eventType_SpriteAnimate action_FadeComplete event when done.

Note
if a previous call was made to wait() the fade animation will not start until the wait is complete
mySprite.fadeTo(0.5, 1000);   // immediately start to fade to 50% opacity over the next second
myOtherSprite.wait(2000).fadeTo(0.5, 1000);  // wait 2 seconds, then fade to 50% opacity
See Also
SpriteAnimateEvent
fadeIn()
fadeOut()
wait()
gear ( Sprite  otherSprite,
number  gearRatio,
number  initialAngle = 0,
number  breakingForce = 0 
)

join two sprites as if they were geared together (Chipmunk Physics Only)

Whenever this sprite spins, it will force the other to spin the same amount (adjusted by the gear ratio).

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of rotational force (torque) is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
Note
this only affects rotation, it does not join them in any other way, so they are still free to move around independently otherwise.
getCollideGroup ( )

see which collide group this sprite is part of (Chipmunk Physics Only)

Items in the same collide group do not collide with one another. Sprites that are connected with joints are automatically assigned to the same collide group.

See Also
setCollideGroup()
getCollisionRadius ( )

get the collision radius for this sprite

See Also
setCollisionRadius()
enableCollisions()
getCurrentFrame ( )

which frame of animation the sprite is currently showing

Returns
the frame index number (0 based)
getElasticity ( )

get the elasticity for this sprite's collisions

See Also
setElasticity()
getFrameCenterOffset ( Image  image = null,
int  frameNum = 0 
)

get the offset to the center-point from the true image center for a given frame

If image is passed in, then frameNum is for that the Nth frame of that image, otherwise frameNum indicates which frame for the sprite

Returns
an Offset
getFrameCount ( )

get number of frames of animation for this sprite

Returns
total number of frames of animation for this sprite
getFrameRotatedBounds ( int  frameNum = -1)

get the bounds of the sprite, including rotation, for a given frame, in layer coordinates. If no frameNum is passed in, or the frame is not present, the bounds of the current frame are returned.

Returns
a RotatedRect with the bounds of the frame in layer coordinates, rotated to match the sprite
Note
use SpriteLayer.layerToPortRect() to convert to drawing coordinates.
See Also
SpriteLayer.layerToPortRect()
getFriction ( )

get the friction used for movement calculations for this sprite (Chipmunk Physics Only)

Note
Chipmunk Physics uses a single friction value, so this replaces Animated's getMove/Spin/SizeFriction() which all just return 0 for Sprite's in builds that are compiled with Chipmunk physics.
Todo:
rethink hiding set/get of Move/Spin/Size friction since we might still want friction in a Chipmunk enabled build for layers that have chipmunk physics turned off.
getLayer ( )

get the layer that contains this sprite

Returns
the containing SpriteLayer
number getMouseDetectMode ( )
getMyClassTag ( )

returns class tag for Sprite, used for serialization

getOpacity ( )

get the level of opacity for this sprite

Returns
opacity, 1.0 being complete opaque and 0.0 being completely transparent
See Also
setOpacity()
fadeIn()
fadeOut()
fadeTo()
getSerializedSize ( Serializer  serializer)

get the bytes needed to serialize the layer

Takes into account the serialization mode of the layer it is in

See Also
SpriteLayer.setSerializationFlags()
boolean getWantsAnimEndEvents ( )
boolean getWantsAnimLoopEvents ( )
boolean getWantsClickEvents ( )
boolean getWantsCollideWallEvents ( )
boolean getWantsMouseOverEvents ( )
boolean getWantsOffscreenEvents ( )
getZOrder ( )

get the z-order of this sprite in the layer it belongs to

0 means furthest back (drawn first)

See Also
isBehind()
moveToBack()
moveToFront()
moveBehind()
moveInFrontOf()
SpriteLayer.getSpriteZOrder()
SpriteLayer.getNthSprite()
grooveJoint ( Offset  grooveStart,
Offset  grooveEnd,
Sprite  otherSprite,
Offset  otherAnchor,
number  breakingForce = 0 
)

join groove on this sprite to an anchor point on another (Chipmunk Physics Only)

optional breaking force at which the joint (and and any other connections to that sprite) are broken

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of force is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
hasAnimation ( int  animationId)

check if a sprite has a particular SCML animation by ID

hasAnimation ( string  animationName)

check if a sprite has a particular SCML animation by name

isBehind ( Sprite  sprite)

returns true if this sprite will be drawn before the given sprite

See Also
getZOrder()
SpriteLayer.isSpriteBehind()
makeJointBreakable ( CpConstraint  joint,
number  breakingForce 
)

set or change force at which the joint between sprites will break (Chipmunk Physics Only)

See Also
makeJointUnbreakable()
SpriteBreakEvent
makeJointUnbreakable ( CpConstraint  joint)

make the joint impossible to break (Chipmunk Physics Only)

Note
sufficient force can still incorrectly stretch a joint, adjust contraint's error bias to fix.
See Also
makeJointBreakable()
CpConstraint.setErrorBias()
makeStatic ( )

make this sprite unaffected by physics (Chipmunk Physics Only)

This sprite becomes a static body that isn't affected by physics, though non-static objects can collide with it. This would be used for walls or platforms.

Warning
This should be done before setting anything else about the sprite
Returns
itself so you can call it on creation
var sprite = layer.createSprite().makeStatic();
motor ( Sprite  otherSprite,
number  spin,
number  maxTorque = INFINITY 
)

keep spin of another sprite at a constant rate compared to this one (Chipmunk Physics Only)

Returns
the cpConstraint in case you want to do anything special with it
moveBehind ( Sprite  sprite)

make this sprite be drawn before another sprite (visually behind)

See Also
moveInFrontOf()
isBehind()
getZOrder()
moveToBack()
moveToFront()
SpriteLayer.getSpriteZOrder()
SpriteLayer.getNthSprite()
moveInFrontOf ( Sprite  sprite)

make this sprite be drawn just after another sprite (visually in front of)

See Also
moveBehind()
isBehind()
getZOrder()
moveToBack()
moveToFront()
SpriteLayer.getSpriteZOrder()
SpriteLayer.getNthSprite()
moveToBack ( )
moveToFront ( )
offsetFrameCenters ( int  offsetX,
int  offsetY,
Image  image = null,
int  startingFrame = start_FromFirstFrame,
int  numFrames = all_Frames 
)

change the center of rotation for the sprite

Normally a sprite rotates around it's visual center, that is, the center-point of each frame of animation. This lets you shift that center of rotation, for all frames, on a per Image basis, or on a frame by frame basis.

Parameters
offsetXthe horizontal offset from true center for the new center-point
offsetYthe vertical offset from the true center for the new center-point
imageif passed, only change the center points for frames using that image, and make frame numbers relative to the Image frames.
startingFrameif passed, only change frames starting at a particular index in the frame list (or Image frame list if image also passed)
numFramesonly change this many frames
Warning
This doesn't work to change the center-point of individual images or frames of an SCML sprite
See Also
getFrameCenterOffset()
on ( int  eventCode,
function  func 
)

set event handler for all different sprite events

See Also
IEventHandler
onAnimationEnd ( function  func)

set event handler for sprite animation end events

These happen when this sprite finishes a particular frame animation sequence, but only if setWantsAnimEndEvents(true) was called

See Also
setWantsAnimEndEvents()
SpriteAnimateEvent
IEventHandler
onAnimationLoop ( function  func)

set event handler for sprite animation loop events

These happen when this sprite finishes a particular frame animation sequence and is restarting it because it is set to loop, but only if setWantsAnimLoopEvents(true) was called.

See Also
setWantsAnimLoopEvents()
SpriteAnimateEvent
IEventHandler
onCollideSprite ( function  func)

set event handler for sprite-to-sprite collision events

The happens whenever this sprite collides with another sprite, but only if enableCollisions() or setCollisionRadius() was called

See Also
enableCollisions()
setCollisionRadius()
SpriteCollideEvent
IEventHandler
onCollideWall ( function  func)

set event handler for sprite-wall collision events

This happens whenever this sprite collides with the boundaries of the layer, but only if setWantsCollideWallEvents(true) was called.

See Also
setWantsCollideWallEvents()
onExitLayer()
SpriteCollideEvent
IEventHandler
onExitLayer ( function  func)

set event handler for sprite out of bounds event

These happen whenever this sprite moves completely outside the boundaries of the layer, but only if setWantsCollideWallEvents(true) was called.

See Also
setWantsCollideWallEvents()
onOffscreen()
onOnscreen()
SpriteAnimateEvent
IEventHandler
onFadeComplete ( function  func)

set event handler for sprite fade event

This happens whenever this sprite completes a fade over time done by fadeTo()

See Also
fadeTo
SpriteAnimateEvent
IEventHandler
onFadeInComplete ( function  func)

set event handler for sprite fade in event

This happens whenever this sprite completes a fade in over time done by a call to fadeIn()

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

set event handler for sprite fade out event

This happens whenever this sprite completes a fade out over time done by a call to fadeOut()

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

set event handler for tap or mouse click in this sprite

Only works if you first call setWantsClickEvents(true).

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

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

Only works if you first call setWantsClickEvents(true).

Note
if you are just looking for a click on a sprite-base button, see onMouseClick(), which handles the mouse down and mouse up events for you.
See Also
setWantsClickEvents()
onMouseUp()
onMouseClick()
SpriteTouchEvent
IEventHandler
onMouseEnter ( function  func)

set event handler for mouse pointer entering this sprite (NOT IMPLEMENTED)

Only works if you first call setWantsMouseOverEvents(true).

See Also
setWantsMouseOverEvents()
onMouseLeave()
SpriteTouchEvent
IEventHandler
Todo:
NOT IMPLEMENTED
onMouseLeave ( function  func)

set event handler for mouse pointer leaving this sprite (NOT IMPLEMENTED)

Only works if you first call setWantsMouseOverEvents(true).

See Also
setWantsMouseOverEvents()
onMouseEnter()
SpriteTouchEvent
IEventHandler
Todo:
NOT IMPLEMENTED
onMouseUp ( function  func)

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

Only works if you first call setWantsClickEvents(true).

See Also
setWantsClickEvents()
onMouseDown()
SpriteTouchEvent
IEventHandler
onOffscreen ( function  func)

set event handler for sprite offscreen event

This happens whenever this sprite moves completely outside the visible area of the port the layer is being rendered in, but only if you first call setWantsOffscreenEvents(true)

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

set event handler for sprite onscreen event

This happens whenever this sprite moves into the visible area of the port the layer is being rendered into, but only if you first call setWantsOffscreenEvents(true)

See Also
setWantsOffscreenEvents()
onOffscreen()
SpriteAnimateEvent
IEventHandler
pinJoint ( Offset  anchor,
Sprite  otherSprite,
Offset  otherAnchor,
number  breakingForce = 0 
)

pin sprites together at a particular anchor point (offset from center) on each (Chipmunk Physics Only)

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of force is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
pivotJoint ( Sprite  otherSprite,
Point  pivot,
number  breakingForce = 0 
)

join sprites together at a particular location in layer coordinates (Chipmunk Physics Only)

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of force is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
ratchet ( Sprite  otherSprite,
number  rachetInterval,
number  phase,
number  breakingForce = 0 
)

join two sprites rotation with a ratchet mechanism (Chipmunk Physics Only)

like a socket wrench. ratchetInterval is the distance between “clicks”, phase is the initial angular offset to use when deciding where the ratchet angles are.

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of rotational force (torque) is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
removeJoint ( CpConstraint  joint)

remove a joint between two sprites (Chipmunk Physics Only)

rotaryLimit ( Sprite  otherSprite,
number  minAngle,
number  maxAngle,
number  breakingForce = 0 
)

limit the angle another sprite can have relative to this one (Chipmunk Physics Only)

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of rotational force (torque) is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
rotarySpring ( Sprite  otherSprite,
number  restAngle,
number  stiffness,
number  damping,
number  breakingForce = 0 
)

keep sprites at a particular angle relative to one another via a rotary spring (Chipmunk Physics Only)

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of rotational force (torque) is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
serialize ( Serializer  serializer)

serialize this sprite into a data stream

Note
uses the SpriteLayer's serialization mode to determine exactly what is serialized
See Also
getSerializedSize()
SpriteLayer.setSerializationFlags()
setCollideGroup ( int  group)

set the collide group this sprite is part of (Chipmunk Physics Only)

Items in the same collide group do not collide with one another. Sprites that are connected with joints are automatically assigned to the same collide group.

See Also
getCollideGroup()
setCollisionHelper ( ISpriteCollideHelper  helper)

set a helper to filter out some collisions for this sprite

Sets up a handler to do special case collision logic between two sprites. For example, you might want bullet sprites to collide with enemy sprites but not with one another. If a collide helper is installed, then on initial contact between two sprites the collide helper for the moving sprite will be called, and your helper can decide if the collision should happen or not.

Parameters
helperan ISpriteCollideHelper instance that will filter some collisions.
Note
You should use other techniques wherever possible to eliminate unnecessary collision helper callbacks, since these callbacks are relatively expensive. You should turn off collisions for sprites that never collide with anything; put sets of sprites that collide only with each other in separate layers; and use collision groups to set up groups of sprites that collide with other things but not each other.
var myHelper = new pdg.ISpriteCollideHelper(function(sprite, withSprite) {
console.log("in my sprite collide helper for " + sprite );
if (withSprite.id == 100) {
return true; // only collide with the player sprite (id 100)
}
return false; // don't collide with anything else
});
mySprite.setCollisionHelper(myHelper);
See Also
ISpriteCollideHelper
setCollisionHelper()
enableCollisions()
disableCollisions()
setCollideGroup()
SpriteLayer.enableCollisions()
SpriteLayer.disableCollisions()
SpriteLayer.enableCollisionsWithLayer()
SpriteLayer.disableCollisionsWithLayer()
setCollisionRadius ( number  pixelRadius)

set the radius of the collision boundary circle of the sprite

The boundary circle is centered at the sprite's location.

Note
Calling this enables collisions and sets the collision mode to collide_collisionRadius, so you don't need to call enableCollisions().
See Also
enableCollisions()
setDrawHelper ( ISpriteDrawHelper  helper)

set a pre-draw helper for custom sprite drawing

Sets a helper to do extra drawing stuff for this Sprite. This helper will be called before the Sprite draws normally, and can block normal sprite drawing by returning false from the helper function.

If you want to do overlay effects, use the post-draw helper for that (see setPostDrawHelper)

Parameters
helperthe pre-draw helper that you want use to add background effects or replace normal rendering of the sprite
var myHelper = new pdg.ISpriteDrawHelper(function(sprite, port) {
console.log("in my sprite draw helper for " + sprite );
var r = sprite.getLayer().layerToPortRect(sprite.getFrameRotatedBounds());
port.fillRect(r, "black");
port.frameRect(r, "white");
return false; // don't let sprite draw itself (ignored for post draw)
});
mySprite.setDrawHelper(myHelper);
See Also
ISpriteDrawHelper
setPostDrawHelper()
Sprite setElasticity ( number  elasticity)
Sprite setEntityScale ( number  xScale,
number  yScale 
)
Sprite setFrame ( int  frame)
Sprite setMouseDetectMode ( int  collisionType = collide_BoundingBox)
Sprite setOpacity ( number  opacity)
setPostDrawHelper ( ISpriteDrawHelper  helper)
Sprite setWantsAnimEndEvents ( boolean  wantsThem = true)
Sprite setWantsAnimLoopEvents ( boolean  wantsThem = true)
Sprite setWantsClickEvents ( boolean  wantsThem = true)
Sprite setWantsCollideWallEvents ( boolean  wantsThem = true)
Sprite setWantsMouseOverEvents ( boolean  wantsThem = true)
Sprite setWantsOffscreenEvents ( boolean  wantsThem = true)
slideJoint ( Offset  anchor,
Sprite  otherSprite,
Offset  otherAnchor,
number  minDist,
number  maxDist,
number  breakingForce = 0 
)

join sprites together via a slider between anchor points that has a min/max distance (Chipmunk Physics Only)

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of force is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
springJoint ( Offset  anchor,
Sprite  otherSprite,
Offset  otherAnchor,
number  restLength,
number  stiffness,
number  damping,
number  breakingForce = 0 
)

join sprites together via a spring between anchor points (Chipmunk Physics Only)

If a breaking force is given, then the joint will break, generating a SpriteBreakEvent, if greater than that amount of force is applied to the joint.

Returns
the cpConstraint for the Joint in case you want to do anything special with it
startAnimation ( int  animationId)
startAnimation ( string  animationName)
startFrameAnimation ( number  fps,
int  startingFrame = start_FromFirstFrame,
int  numFrames = all_Frames,
int  animateFlags = animate_Looping 
)
stopFrameAnimation ( )
useCollisionMask ( Image  frameImage,
Image  maskImage 
)

User Comments