MapActor API Reference


b5.MapActor

A MapActor is derived from an Actor and displays a tile map based game object instead of an image and inherits all properties, functions and so forth from its parent. A MapActor should be added to a Scene or another Actor once created.

Public Properties

  • tiles – The tile set array, each tile contains {x, y} which represents the top left hand corner of the tile in the source bitmap
  • map – An array of tile indices into the tiles set that represents the visual map
  • collision_map – An array of collision tile indices into the collision tiles set that represents the collision map
  • tile_width – Width of tiles in the tile set
  • tile_height – Height of tiles in the tile set
  • map_width – Width of map in cells
  • map_height – Height of map in cells
  • display_width – Number of cells to display across the screen
  • display_height – Number of cells to display down the screen

Methods

MapActor() – Creates an instance of a MapActor object

draw() – Draws an arc actor and its children, this method can be overridden by derived actors

generateTiles(count, tile_w, tile_h, bitmap_w) – Generates a tile set from the supplied parameters

  • count – Total tiles to generate
  • tile_w – Width of each generated tile
  • tile_h – Height of each generated tile
  • bitmap_w – Width of the source tile bitmap

setTile(x, y, tile, collision) – Sets the tile at cell x,y

  • x – Map horizontal cell coordinate
  • y – Map vertical cell coordinate
  • tile – Tile number
  • collision – If true then tile in the collision map will be written instead of visual map

getTile(x, y, collision) – Gets the tile at cell x,y

  • x – Map horizontal cell coordinate
  • y – Map vertical cell coordinate
  • collision – If true then returned tile will be taken from collision map instead of visual map
  • returns tile at coordinate

getTileXY(x, y) – Converts the supplied scene coordinate to a map cell coordinate

  • x – x-axis coordinate in scene space
  • y – y-axis coordinate in scene space
  • returns {x, y} map coordinate

getTilePosition(x, y) – Calculates the scene coordinate for the specified edge of a tile

  • x – x-axis coordinate in scene space
  • y – y-axis coordinate in scene space
  • position – Can be one of the following strings:
    • t – Returns coordinate of top edge of tile
    • m – Returns coordinate of middle of tile
    • b – Returns coordinate of bottom edge of tile
    • l – Returns coordinate of left edge of tile
    • c – Returns coordinate of centre of tile
    • r – Returns coordinate of right edge of tile
  • returns {x, y} map coordinate of tile edge

getTileFromPosition(x, y, collision) – Gets the tile at cell position x, y

  • x – Scene coordinate on x-axis
  • y – Scene coordinate on y-axis
  • collision – If true then returned tile will be taken from collision map instead of visual map
  • returns tile at coordinate

Examples

 

1,125 total views, 1 views today