Spritesheet

A spritesheet with animation support

Events

NameDescriptionArguments
loadSpritesheet is fully loaded and ready to useNone
addSpritesheet is added to the rendererNone
deleteSpritesheet is removed from the rendererNone

Constructor

new Spritesheet(options)

Creates a new Spritesheet

Parameters:
NameTypeDescription
optionsObject

Spritesheet options

Example
// Includes all Spritesheet options
new Spritesheet({
	container: game.Render.app.stage, // PIXI Container
	layer: 0,
	position: new vec(0, 0),
	angle: 0,

	visible: true,
	alpha: 1,
	speed: 1 / 6,
	src: "",
	animation: "",
	
	scale: new vec(1, 1),
	width:  undefined, // Number | undefined
	height: undefined, // Number | undefined
});

Extends

Members

(readonly) nodeType

Type of node, ie Node or RigidBody

Overrides

(readonly) position :vec

Position of the node

Type:
Overrides
To Do
  • Implement getPosition method and make this private

(readonly) angle :number

Angle, in radians

Type:
  • number
Overrides
To Do
  • Implement getAngle method and make this private

(readonly) children :Set

Children of the node To modify, use addChild or removeChild.

Type:
  • Set
Overrides

Methods

add()

Adds the sprite to the world

Overrides

delete()

Removes the sprite from the world

Overrides

setSpeed(speed)

Sets the animation's speed

Parameters:
NameTypeDescription
speedNumber

setLayer(layer)

Sets the render layer (z index)

Parameters:
NameTypeDescription
layernumber

Render layer (z index) for the render

setScale(scale)

Sets the sprite's scale

Parameters:
NameTypeDescription
scalevec

New scale

setSize(width, height)

Sets the sprite's width and height

Parameters:
NameTypeDescription
widthnumber

New width

heightnumber

New height

setAlpha(alpha)

Sets the sprite's alpha

Parameters:
NameTypeDescription
alphanumber

Opacity, between 0 and 1 inclusive

setVisible(visible)

Changes if the sprite is visible

Parameters:
NameTypeDescription
visibleboolean

If the sprite is visible

translate(delta)

Shifts the sprite's position by delta

Parameters:
NameTypeDescription
deltavec

Amount sprite is shifted by

translateAngle(angle)

Rotates the sprite relative to current angle

Parameters:
NameTypeDescription
anglenumber

Amount to rotate sprite, in radians

destroy()

Destroys the sprite. Use when you know the sprite will no longer be used

on(event, callback)

Binds a function to an event

Parameters:
NameTypeDescription
event"load" | "add" | "delete"

Name of the event

callbackfunction

Function called when event fires

Overrides

off(event, callback)

Unbinds a function from an event

Parameters:
NameTypeDescription
event"load" | "add" | "delete"

Name of the event

callbackfunction

Function bound to event

Overrides

trigger(event)

Fires an event

Parameters:
NameTypeDescription
event"load" | "add" | "delete"

Name of the event

Overrides

isAdded() → {Boolean}

Gets if the node is added

Overrides
Returns:

if the node is added

Type: 
Boolean

addChild(…children)

Adds all children to this node's children

Parameters:
NameTypeAttributesDescription
childrenNode<repeatable>

Children added

Overrides
Example
let parentNode = new Node();
let childNode = new Node();
node.addChild(childNode);

removeChild(…children)

Removes all children from this node's children

Parameters:
NameTypeAttributesDescription
childrenNode<repeatable>

Children removed

Example
let parentNode = new Node();
let childNode = new Node();
node.addChild(childNode); // node.children: Set {childNode}
node.removeChild(childNode); // node.children: Set {}

setPosition(position)

Sets this node's position to position

Parameters:
NameTypeDescription
positionvec

Position the node should be set to

Example
node.setPosition(new vec(100, 100)); // Sets node's position to (100, 100) 

setAngle(angle)

Sets the node's angle to angle

Parameters:
NameTypeDescription
anglenumber

Angle body should be in radians

Overrides
Example
node.setAngle(Math.PI); // Sets node's angle to Pi radians, or 180 degrees