Class Scene

Constructors

Properties

camera: Camera = ...

The camera object for the scene.

data: Record<string, any> = {}

The custom data for the scene.

game: Game

The game object that the scene belongs to.

gravity: number = 0

The global gravity value for the scene.

layers: Layer[] = []

An array of all the layers in the scene.

name: string

The name of the scene.

nextRenderOrder: number = 0

The next available render order for layers.

objects: Entity[] = []

An array of all the objects in the scene.

size: Vector = ...

The size of the scene (grid size in tiles). Default grid is canvas resolution with tile size 1px.

tileCollisionData: number[] = []

An array of tile collision data.

tileSize: Vector = ...

The size of each tile in the scene (default 1px).

tiles: Record<string, Tile> = {}

A record of all the tiles in the scene.

tmxMap?: string

The TMX map file name.

Methods

  • Adds a layer to the scene.

    Parameters

    • l: TMXLayer | Constructable<Layer>

      The layer to add. It can be a constructor function or an instance of TMXLayer.

    • Optionalorder: number

      The render order of the layer. If not provided, it will be assigned the next available render order.

    Returns Layer

  • Adds an entity to the scene.

    Parameters

    • entity: Entity

      The entity to be added.

    • OptionallayerId: number

      The ID of the layer to add the entity to (optional).

    Returns Entity

    The added entity.

  • Adds an object to the scene from a specific layer.

    Parameters

    • type: string

      The type of the object to add.

    • props: Record<string, any>

      The properties of the object.

    Returns Entity

    The added entity.

  • Adds a tileset to the scene.

    Parameters

    • tileset: TMXTileset

      The tileset to add.

    • source: string

      The source of the tileset image.

    Returns {
        columns: number;
        firstgid: number;
        image: {
            height: number;
            source: string;
            width: number;
        };
        margin?: number;
        name: string;
        spacing?: number;
        tilecount: number;
        tileheight: number;
        tiles: TMXTile[];
        tilewidth: number;
    }

    • columns: number
    • firstgid: number
    • image: {
          height: number;
          source: string;
          width: number;
      }
      • height: number
      • source: string
      • width: number
    • Optionalmargin?: number
    • name: string
    • Optionalspacing?: number
    • tilecount: number
    • tileheight: number
    • tiles: TMXTile[]
    • tilewidth: number
  • Creates a scene from a TMX map.

    Parameters

    • tmxMap: TMXTiledMap

      The TMX map to create the scene from.

    Returns void

  • Creates tilesets for the scene.

    Parameters

    • tilesets: TMXTileset[]

      An array of TMXTileset objects representing the tilesets to be created.

    Returns void

  • Retrieves the value associated with the specified key from the data object.

    Parameters

    • key: string

      The key of the value to retrieve.

    Returns any

    The value associated with the specified key, or undefined if the key does not exist.

  • Retrieves a layer from the scene based on the provided ID.

    Parameters

    • id: number

      The ID of the layer to retrieve.

    Returns undefined | Layer

    The layer with the specified ID, or undefined if no layer is found.

  • Retrieves the layer at the specified index. If the layer does not exist, an empty Layer object is returned.

    Parameters

    • index: number

      The index of the layer to retrieve.

    Returns Layer

    The layer at the specified index, or an empty Layer object if the layer does not exist.

  • Retrieves an object from the scene by its ID.

    Parameters

    • id: number

      The ID of the object to retrieve.

    Returns undefined | Entity

    The object with the specified ID, or undefined if not found.

  • Retrieves an object from the scene by its type.

    Parameters

    • type: string

      The type of the object to retrieve.

    Returns undefined | Entity

    The first object found with the specified type, or undefined if no object is found.

  • Returns an array of objects of a specific type.

    Parameters

    • type: string

      The type of objects to filter.

    Returns Entity[]

    An array of objects of the specified type.

  • Retrieves the tile object at the specified position on the given layer. If the tile at the position is not found, it returns the tile object at index 0.

    Parameters

    • pos: Vector

      The position of the tile.

    • layerId: number

      The ID of the layer.

    Returns undefined | Tile

    The tile object at the specified position.

  • Retrieves the tile collision data at the specified position.

    Parameters

    • pos: Vector

      The position to retrieve the tile collision data from.

    Returns number

    The tile collision data at the specified position.

  • Retrieves the tile object with the specified ID.

    Parameters

    • id: number

      The ID of the tile object.

    Returns Tile

    The tile object associated with the ID.

  • Performs a raycast to check for tile collisions between two positions. Based on the DDA algorithm: https://lodev.org/cgtutor/raycasting.html

    Parameters

    • start: Vector

      The starting position of the raycast.

    • end: Vector

      The ending position of the raycast.

    • Optionalentity: Entity

      An optional entity to check for collisions with tiles.

    Returns undefined | Vector

    The position of the first tile hit by the raycast, or null if no collision occurred.

  • Sets the value of a specific key in the data object.

    Parameters

    • key: string

      The key to set the value for.

    • value: any

      The value to set.

    Returns void

  • Sets the collision data for a tile at the specified position.

    Parameters

    • pos: Vector

      The position of the tile.

    • data: number = 0

      The collision data to set for the tile. Defaults to 0.

    Returns void

  • Sets the tile collision layer for the scene.

    Parameters

    • layerId: number

      The ID of the layer to set as the collision layer.

    • exclude: number[] = ...

      An array of tile IDs to exclude from the collision layer.

    Returns void

  • Performs a tile collision test for the given position and size.

    Parameters

    • pos: Vector

      The position of the entity.

    • size: Vector

      The size of the entity.

    • Optionalentity: Entity

      The entity to perform the collision test for (optional).

    Returns boolean

    true if a collision is detected, false otherwise.