API Docs for: 0.3.0
Show:

Graphic.AnimatedSprite Class

The AnimatedSprite allows you to create an object which can be animated using a SpriteSheet.

When you instanciate a new AnimatedSprite instance, you have to pass it the SpriteSheet which it will have to use.

The spritesheet represent the configuration of all animations and how to play them. An AnimatedSprite instance is an object which can be displayed, and can play animations. several AnimatedSprite with the same animation should use the same shared SpriteSheet.

An animation can be started with play() and stopped with stop(). For managing animations, you can assign a callback when an animation is ended:

sprite.play("running", false, function(loop, anim, sprite, status) {
    if (status == "END:STOP") {
         console.log("Stop running, i'll walk.");
         sprite.play("walking", true);
    }
});

Constructor

Graphic.AnimatedSprite

(
  • params
)

Parameters:

  • params Object

    params is given to GraphicObject constructor.

    • spriteSheet SpriteSheet

      it is a SpriteSheet object which contains one or severals animation which can be used by the current AnimatedSprite object.

Methods

_setCenterPointByHotPoint

(
  • currentAnim
)
private

This method is private and associate to the animated sprite the hotpoint

Parameters:

  • currentAnim Object

    current animation of the Animated Sprite.

draw

(
  • context
)
Boolean

This method allow you to draw an animated sprite on a context.

Parameters:

  • context Object

    this parameter must be a valid canvas context, otherwise the behavior of the draw method is unspecified.

Returns:

Boolean: this methods return true if the context parameter is a valid object and if the sprite's image is also a validSpriteSheet.

getCurrentAnim

() Object

The getCurrentAnim returns the current animation which is currently played.

Returns:

Object: returns the animation which is played. If there is no animations currently played then the getCurrentAnim method will returns null.

isPlaying

() Boolean

The isPlaying method allows you to test if the current AnimatedSprite object is playing or not an animation.

Returns:

Boolean: returns true if the current AnimatedSprite object is playing an animation, otherwise it returns false.

notifyParentChange

() protected

This method notify the parent that a change has been done, and that it should clear his cache.

pause

()

The pause method allows you to pause the current animation until the resume method is called.

play

(
  • name
  • loop
  • callback
)

the play method allows you to start an animation (note that this animation must be defined inside of the SpriteSheet object currently used by the AnimatedSprite).

Parameters:

  • name String

    string parameter which represents the name of the animation to start

  • loop Boolean

    boolean parameter which set looping the animation if set to true. Otherwise, looping is disabled.

  • callback Function

    function which is called each time the animation reach it's end. Callback take one parameter which is an object which contains the following parameters :

    • loop Boolean

      a boolean which represent the loop status of the animation, if loop true then the animation will loop when its reach its end.

    • anim String

      a string which represent the name of the animation which reach end.

    • sprite AnimatedSprite

      a reference to the animated sprite which called the callback

    • status String

      a string which represent the status of the callback, status can have the following values :

      • "END:LOOP" the AnimatedSprite will loop
      • "END:STOP" the AnimatedSprite is now stopped,
      • "PAUSE" the AnimatedSprite is now paused
      • "RESUME" the animated sprite is now resumed

resume

()

The resume method allows you to resume the current animation if it has been pause before.

rotate

(
  • angle
)
chainable

This method allow you to rotate the Graphical object around the center point of the GraphicalObject.

Parameters:

  • angle Number

    represent the angle of rotation, it's expressed in degree.

scale

(
  • x
  • y
)
chainable

this method allow you to do a scale on the GraphicObject.

Parameters:

  • x Number

    this is the x scale factor

  • y Number

    this is the y scale factor

setAttr

(
  • attrs
)
chainable

Setter availlable for updating attibuts and correctly clear the caches. You can set all attributes supported by this instance (see the GraphicObject constructor for common available properties)

Parameters:

  • attrs Object

    GraphicObject attributs. See the constructor for more details.

Example:

 object.setAttr({
     width: 20,
     height: 20
 });

 object.setAttr({
     pos: {
         x: 0,
         y: 0
     }
 });

skew

(
  • a
  • b
)
chainable

This method allow you to do a skew transform on the GraphicObject.

Parameters:

  • a Number

    the factor of skew on the y axis

  • b Number

    the factor of skew on the x axis

stop

()

The stop method allows you to stop and then rewind the current animation.

translate

(
  • x
  • y
)
chainable

This method allow you to translate the GraphicalObject, Internally this method modify the GraphicObject's matrix.

Parameters:

  • x Number

    this is the translation scalar of the x axis.

  • y Number

    this is the translation scalar of the y axis.

update

() Boolean

The update method is called each frame by the gameloop.

Returns:

Boolean: return true if the update function has been called successfully, otherwise false is returned.

Properties

alpha

Number

value of opacity, between 0.0 (fully transparent) and 1.0 (opaque)

centerPoint

Object

default center of all matrix transformations.

values are exprimed depending on the size of the object. 0;0 is the up-left corner.

Sub-properties:

  • x Object
  • y Object

matrix

Matrix

matrix applied to this object before draw.

parent

Layer

parent containing this object.

spriteSheet

SpriteSheet

a SpriteSheet object which contains one or severals animation which can be used by the current AnimatedSprite object.

x

Number

position on X axis

y

Number

position on Y axis

zIndex

Number

zIndex, used to determine the drawing order. Hight zIndex are drawn first.