Constructors

Fields Summary

TilemapCharacter._gamepadStates

Current state of the gamepad to base movement off
TilemapCharacter._keyStates

Current state of the keys to base movement off
TilemapCharacter.allowDiagonal

Whether or not to allow diagonal movement, true by default
TilemapCharacter.allowInput

A flag that specifies if the character can be controlled by player input
TilemapCharacter.animations

Specify the animation names to use for various walking and idle states
TilemapCharacter.automaticRotations

Automatically rotates object to match movement
TilemapCharacter.controls

Keyboard keys to control the character. By default arrow keys are used
TilemapCharacter.gamePadControls

Axis and direction of gamepad controls
TilemapCharacter.gamePadIndex

The game pad to use
TilemapCharacter.movementSpeed

The movement speed of the character (in world units per second). Note that changing this won't affect any movement that is currently in progress, only future movements. Default is 160.
TilemapCharacter.name

The name of the behavior. This is set to 'TilemapCharacter'.
TilemapCharacter.rotationOffset

Used for automatic rotations. A sprite can have any orientation
TilemapCharacter.velocity

Current velocity of the object

Functions Summary

TilemapCharacter._inputState (direction)

Looks at both keyboard and gamepad state data to determine movement
TilemapCharacter.boxInGrid (box)

TilemapCharacter.calcFutureCoords (pos, vel)

Applies one tick of velocity to the position, and returns the final cell co-ordinates
TilemapCharacter.clearDestinations ()

Remove any destinations that were added with setDestination()
TilemapCharacter.generateCollisionBox ()

Constructs a collision box based on the bounding boxes of all sprites belonging to the scene object.
TilemapCharacter.getNextDestination ()

Get the next destination
TilemapCharacter.handleTileTransition (futureCoords)

Tests and handles moving into a new tile
TilemapCharacter.illegalTile (dest, exception)

Returns true if either the tile is off the grid, or the tile contains a collidable object
TilemapCharacter.inGrid (x, y)

Helper Function - Returns whether the co-ordinates are inside the tilemap boundary
TilemapCharacter.onAddToScene (params)

Initialises the collision box and sets the local rotation value from the parent
TilemapCharacter.onKeyDown (data)

Updates keyboard state
TilemapCharacter.onKeyUp (data)

Updates keyboard state
TilemapCharacter.onUpdate ()

Update character state based on user input
TilemapCharacter.overlappingTerrainTiles (displace)

Returns tile co-ordinates of all terrain tiles overlapping the character
TilemapCharacter.setDestination (gridCoords)

Set a destination (a tile to move to) for the character.
TilemapCharacter.setRotationOffset (offset)

Calculates the rotations needed for the character
TilemapCharacter.updateAnimation (direction, noMove)

Plays the correct animation depending on the control input state
TilemapCharacter.updateGamepadState ()

Samples the gamepad to get the current states of the buttons and axis
TilemapCharacter.updateVelComponent (noMove, vel, direction)

Adds a direction velocity, taking into account diagonal motion
TilemapCharacter.updateVelocity ()

Updates the velocity and calculates the closest direction for the animation system
TilemapCharacter.velocityToDirection (vel)

Returns the closest movement direction given a provided velocity

Fields Details

TilemapCharacter._gamepadStates

Current state of the gamepad to base movement off
^
TilemapCharacter._keyStates

Current state of the keys to base movement off
^
TilemapCharacter.allowDiagonal

Whether or not to allow diagonal movement, true by default
^
TilemapCharacter.allowInput

A flag that specifies if the character can be controlled by player input
^
TilemapCharacter.animations

Specify the animation names to use for various walking and idle states
^
TilemapCharacter.automaticRotations

Automatically rotates object to match movement
^
TilemapCharacter.controls

Keyboard keys to control the character. By default arrow keys are used
^
TilemapCharacter.gamePadControls

Axis and direction of gamepad controls
^
TilemapCharacter.gamePadIndex

The game pad to use
^
TilemapCharacter.movementSpeed

The movement speed of the character (in world units per second). Note that changing this won't affect any movement that is currently in progress, only future movements. Default is 160.
^
TilemapCharacter.name

The name of the behavior. This is set to 'TilemapCharacter'.
^
TilemapCharacter.rotationOffset

Used for automatic rotations. A sprite can have any orientation
This offset is used when calculate the rotation angles for each direction
^
TilemapCharacter.velocity

Current velocity of the object
^

Function Details

TilemapCharacter._inputState (direction)

Looks at both keyboard and gamepad state data to determine movement

direction : The direction we are wanting to move


Returns * : Whether or not there is input for the provided direction

@private
^
TilemapCharacter.boxInGrid (box)



box : Takes a bounding box in the form (minX, minY, maxX, maxY}


Returns boolean : Returns true if the bounding box is completely inside the tilemap area

^
TilemapCharacter.calcFutureCoords (pos, vel)

Applies one tick of velocity to the position, and returns the final cell co-ordinates

pos : The current position


vel : The current velocity in units per second


Returns * : The cell co-ordinates we will be in

^
TilemapCharacter.clearDestinations ()

Remove any destinations that were added with setDestination()
^
TilemapCharacter.generateCollisionBox ()

Constructs a collision box based on the bounding boxes of all sprites belonging to the scene object.

Returns object : Returns a collision box of form {minX, minY, maxX, maxY}

^
TilemapCharacter.getNextDestination ()

Get the next destination

Returns Object : An object with x and y fields representing the next destination, or null if there are no destinations in the queue

^
TilemapCharacter.handleTileTransition (futureCoords)

Tests and handles moving into a new tile

futureCoords : The characters co-ordinates after velocity has been applied in world space

^
TilemapCharacter.illegalTile (dest, exception)

Returns true if either the tile is off the grid, or the tile contains a collidable object

dest : Co-ordinates of the tile to test


Returns boolean|* : Is the move illegal

^
TilemapCharacter.inGrid (x, y)

Helper Function - Returns whether the co-ordinates are inside the tilemap boundary

x : The x cell co-ordinate


y : The y cell co-ordinate


Returns boolean : Returns true if co-ordinates exist on map

^
TilemapCharacter.onAddToScene (params)

Initialises the collision box and sets the local rotation value from the parent
If drawCollisionBox flag is true, draws the debug collision box

Returns object : Returns a collision box of form {minX, minY, maxX, maxY}

^
TilemapCharacter.onKeyDown (data)

Updates keyboard state

data : Event data that specifies keyCode among other things


Returns : {boolean}

^
TilemapCharacter.onKeyUp (data)

Updates keyboard state

data : Event data that specifies keyCode among other things


Returns : {boolean}

^
TilemapCharacter.onUpdate ()

Update character state based on user input
^
TilemapCharacter.overlappingTerrainTiles (displace)

Returns tile co-ordinates of all terrain tiles overlapping the character

Returns Array : The terrain tile co-ordinates

^
TilemapCharacter.setDestination (gridCoords)

Set a destination (a tile to move to) for the character.

{x: number, y: number} gridCoords : The tilemap coordinates to move to


Returns boolean : Whether it was possible to add the destination (i.e. it isn't blocked by objects with collisions)

^
TilemapCharacter.setRotationOffset (offset)

Calculates the rotations needed for the character

offset : The rotation offset to use when automatic rotations is enabled

^
TilemapCharacter.updateAnimation (direction, noMove)

Plays the correct animation depending on the control input state

direction : A string represent the compass direction that most closely matches the characters movement


noMove : A flag specifying that no input controls are active

^
TilemapCharacter.updateGamepadState ()

Samples the gamepad to get the current states of the buttons and axis
If buttons are pressed, the state is stored in this._gamepadStates
Analog values that exceed a threshold value are also stored as true in this._gamepadStates
^
TilemapCharacter.updateVelComponent (noMove, vel, direction)

Adds a direction velocity, taking into account diagonal motion

noMove : Whether or not a velocity component has already been added


vel : The current velocity


direction : A string representing the compass direction

^
TilemapCharacter.updateVelocity ()

Updates the velocity and calculates the closest direction for the animation system

Returns {noMove: boolean, vel: {x: number, y: number}, direction: *} : Data relevant to resolving movement

^
TilemapCharacter.velocityToDirection (vel)

Returns the closest movement direction given a provided velocity

vel : Velocity or unit vector to calculate direction from

^