API Docs for: v0.1.1
Show:

Tile Class

Extends Sprite
Defined in: src\tilemap\Tile.js:4

Base Tile implementation, a tile is a single tile in a tilemap layer

Constructor

Tile

(
  • texture
)

Parameters:

  • texture Texture

    The texture of the tile

Methods

addAnimation

(
  • name
  • frames
  • [speed]
  • [loop]
)
Sprite chainable

Adds a new animation to this animated sprite

Parameters:

  • name String

    The string name of the animation

  • frames Array

    The array of texture frames

  • [speed] Number optional

    The animation speed

  • [loop] Boolean optional

    Loop the animation or not

Returns:

Sprite:

Returns itself.

clone

() Sprite

Creates a new Sprite instance with the same values as this one

Returns:

Sprite:

Returns the new sprite

destroy

()

Removes this sprite from the stage and the physics system

disablePhysics

(
  • callback
)
Mixed chainable async

Inherited from PhysicsTarget but overwritten in src\physics\PhysicsTarget.js:97

Disbales physics for this sprite

Parameters:

  • callback Function

    The callback function to call after physics have been disabled

Returns:

Mixed:

Returns itself.

emit

(
  • type
  • data
)
Mixed chainable

Emits an event which will run all registered listeners for the event type

Parameters:

  • type String

    The event name to emit

  • data Mixed

    Any data you want passed along with the event

Returns:

Mixed:

Returns itself.

enablePhysics

(
  • system
  • callback
)
Mixed chainable async

Enables physics for this sprite

Parameters:

  • system PhysicsSystem

    The system for the sprite to be in

  • callback Function

    The callback function to call after physics have been enabled

Returns:

Mixed:

Returns itself.

goto

(
  • frame
  • [name]
)
Sprite chainable

Goes to a frame and starts playing the animation from there. You can optionally pass the name of a new aniamtion to start playing.

Parameters:

  • frame Number

    The index of the frame to start on

  • [name] String optional

    The string name of the animation to go to

Returns:

Sprite:

Returns itself.

hide

() Sprite chainable

Sets the sprite to visible = false

Returns:

Sprite:

Returns itself.

off

(
  • type
  • listener
)
Mixed chainable

Removes a listener function for an event type

Parameters:

  • type String

    The event name to emit

  • listener Function

    The function to remove

Returns:

Mixed:

Returns itself.

on

(
  • type
  • listener
)
Mixed chainable

Registers a listener function to be run on an event occurance

Parameters:

  • type String

    The event name to listen for

  • listener Function

    The function to execute when the event happens

Returns:

Mixed:

Returns itself.

once

(
  • type
  • listener
)
Mixed chainable

Registers a one-time callback for an event

Parameters:

  • type String

    The event name to listen for

  • listener Function

    the callback to call when the event occurs

Returns:

Mixed:

Returns itself.

play

() Sprite chainable

Starts playing the currently active animation

Returns:

Sprite:

Returns itself.

setMass

(
  • mass
)
Mixed chainable

Sets the mass of this sprite

Parameters:

  • mass Number

    The new mass of the object

Returns:

Mixed:

Returns itself.

setPosition

(
  • x
  • y
)
Mixed chainable

Sets the position of this sprite

Parameters:

  • x Number | Vector

    The x coord to set position to, if a Vector is passed the y param is ignored

  • y Number

    The y coord to set position to

Returns:

Mixed:

Returns itself.

setRotation

(
  • rotation
)
Mixed chainable

Sets the rotation of this sprite

Parameters:

  • rotation Number

    The new rotation of the object in radians

Returns:

Mixed:

Returns itself.

setVelocity

(
  • x
  • y
)
Mixed chainable

Sets the velocity of this sprite

Parameters:

  • x Number | Vector

    The x coord to set the velocity to, if a Vector is passed the y param is ignored

  • y Number

    The y coord to set the velocity to

Returns:

Mixed:

Returns itself.

show

() Sprite chainable

Sets the sprite to visible = true

Returns:

Sprite:

Returns itself.

stop

() Sprite chainable

Stops playing the currently active animation

Returns:

Sprite:

Returns itself.

updateTransform

() private

Called by PIXI to update our textures and do the actual animation

Properties

_phys

Object private

The physics namespace that all physics properties go into. Those properties are:

  • system {PhysicsSystem} PhysicsSystem that this object is a part of.
  • active {Boolean} Whether or not this target is actively having physics simulated.

Default: {}

_velocity

Vector private

The internal velocity value, used as a reusable vector for the setVelocity function. Setting this directly has no effect.

animations

Object

The registerd animations for this AnimatedSprite

currentAnimation

String

The currently playing animation

currentFrame

Number

The current frame being shown

inertia

Number

The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)

Default: 0

lifetime

Number private

The lifetime of the sprite. Once it reaches 0 (after being set) the sprite's visible property is set to false, so that it will no longer be rendered. NOT YET IMPLEMENTED

Default: Infinity

loop

Boolean

Whether or not to loop the animations. This can be overriden on a per-animation level

Default: false

mass

Number

The mass of this object, please use setMass to set this value

Default: 0

name

String

The name of the sprite

Default: ''

playing

Boolean

Whether or not the animation is currently playing

speed

Number

The animation speed for this sprite

Default: 1

Events

click

A callback that is used when the users clicks on the sprite with their mouse

Event Payload:

  • interactionData InteractionData

collision

On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for

Event Payload:

  • obj Sprite

    Colliding sprite

  • vec Vector

    Collision vector (for sensors this is normalized)

  • colShape cp.Shape

    The colliding physics shape

  • myShape cp.Shape

    Your physics shape that caused the collision

complete

Fired when the running animation completes

Event Payload:

  • animation String

    The animation that has completed

frame

Fired when a new frame of the running animation is shown

Event Payload:

  • animation String

    The animation name that is playing

  • frameId Number

    The frame that is being shown

mousedown

A callback that is used when the user clicks the mouse down over the sprite

Event Payload:

  • interactionData InteractionData

mousemove

A callback that is used when the user moves the mouse while over the sprite

Event Payload:

  • interactionData InteractionData

mouseout

A callback that is used when the users mouse leaves the sprite

Event Payload:

  • interactionData InteractionData

mouseover

A callback that is used when the users mouse rolls over the sprite

Event Payload:

  • interactionData InteractionData

mouseup

A callback that is used when the user releases the mouse that was over the sprite for this callback to be fired the mouse must have been pressed down over the sprite

Event Payload:

  • interactionData InteractionData

mouseupoutside

A callback that is used when the user releases the mouse that was over the sprite but is no longer over the sprite for this callback to be fired, The touch must have started over the sprite

Event Payload:

  • interactionData InteractionData

separate

On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for

Event Payload:

  • obj Sprite

    Colliding sprite

  • colShape cp.Shape

    The colliding physics shape

  • myShape cp.Shape

    Your physics shape that caused the collision

tap

A callback that is used when the users taps on the sprite with their finger basically a touch version of click

Event Payload:

  • interactionData InteractionData

touchend

A callback that is used when the user releases a touch over the sprite

Event Payload:

  • interactionData InteractionData

touchendoutside

A callback that is used when the user releases the touch that was over the sprite for this callback to be fired, The touch must have started over the sprite

Event Payload:

  • interactionData InteractionData

touchstart

A callback that is used when the user touch's over the sprite

Event Payload:

  • interactionData InteractionData