Skip to content
On this page

RpgSprite

Each time an event or player appears on the map, an RpgSprite is called. It contains the graphics of the player but also a container to put tiles of the map on top of the sprite (for overlay). Don't pay attention to this system, it is part of the RpgJS engine.

However, RpgSprite inherits from PIXI.Sprite. This way, you can add other containers, etc. This way, you can add other containers, etc.

Put the created class in the RpgClient decorator

Hooks

ts
import { RpgSprite, RpgSpriteHooks } from '@rpgjs/client'

const sprite: RpgSpriteHooks = {
    onInit(sprite: RpgSprite) {

    }
}

onInit

  • Property: onInit
  • Type: (sprite: RpgSprite) => any
  • Optional: true
  • Usage:

As soon as the sprite is initialized


onDestroy

  • Property: onDestroy
  • Type: (sprite: RpgSprite) => any
  • Optional: true
  • Usage:

Called when the sprite is deleted


onChanges

  • Property: onChanges
  • Type: (sprite: RpgSprite, data: any, old: any) => any
  • Optional: true
  • Usage:

As soon as a data is changed on the server side (the name for example), you are able to know the new data but also the old data.


onUpdate

  • Property: onUpdate
  • Type: (sprite: RpgSprite, obj: any) => any
  • Optional: true
  • Usage:

At each tick, the method is called


onMove

  • Since: 3.0.0-beta.4
  • Property: onMove
  • Type: (sprite: RpgSprite) => any
  • Optional: true
  • Usage:

When the x, y positions change

RpgSprite

Summary


guiDisplay

  • Since: 3.0.0-beta.5
  • Property: guiDisplay
  • Type: boolean
  • Optional: false
  • Usage:

Display/Hide the GUI attached to this sprite

RpgSpriteLogic


Get Collision of shapes

  • Since: 3.2.0
  • Property: shapes
  • Type: RpgShape[]
  • Optional: false
  • Read Only
  • Usage:

Recovers all the colliding shapes of the current player


Get Collision of tiles

  • Since: 3.0.0-beta.4
  • Property: tiles
  • Type: TileInfo[]
  • Optional: false
  • Read Only
  • Usage:

Recovers all the colliding tiles of the current player


Get Collision of other players/events

  • Since: 3.0.0-beta.4
  • Property: otherPlayersCollision
  • Type: RpgPlayer | RpgEvent)[]
  • Optional: false
  • Read Only
  • Usage:

Recovers all other players and events colliding with the current player's hitbox


Get Tile

  • Since: 3.0.0-beta.4
  • Method: player.getTile(x,y,z?)
  • Arguments:
    • {number} x. (Optional: false)
    • {number} y. (Optional: false)
    • {number} z. (Optional: true)
  • Return: object
  • Usage:

Retrieves a tile and checks if the player has a collision

ts
const tileInfo = player.getTile(20, 30)
console.log(tileInfo)

Example of returns:

ts
{
      tiles: [
          {
              id: 0,
              terrain: [],
              probability: null,
              properties: [Object],
              animations: [],
              objectGroups: [],
              image: null,
              gid: 1
          }
      ],
      hasCollision: false,
      isOverlay: undefined,
      objectGroups: [],
      isClimbable: undefined,
      tileIndex: 93
  }

Get Shapes

  • Since: 3.0.0-beta.3
  • Method: player.getShapes()
  • Return: RpgShape[]
  • Usage:

Returns all shapes assigned to this player