TileMap

Inherits: Node2D < CanvasItem < Node < Object

Category: Core

Brief Description

Node for 2D tile-based maps.

Member Functions

void clear ( )
int get_cell ( int x, int y ) const
Vector2 get_cell_size ( ) const
int get_cellv ( Vector2 position ) const
bool get_center_x ( ) const
bool get_center_y ( ) const
bool get_clip_uv ( ) const
float get_collision_bounce ( ) const
float get_collision_friction ( ) const
int get_collision_layer ( ) const
bool get_collision_layer_bit ( int bit ) const
int get_collision_mask ( ) const
bool get_collision_mask_bit ( int bit ) const
bool get_collision_use_kinematic ( ) const
Transform2D get_custom_transform ( ) const
int get_half_offset ( ) const
int get_mode ( ) const
int get_occluder_light_mask ( ) const
int get_quadrant_size ( ) const
int get_tile_origin ( ) const
TileSet get_tileset ( ) const
Array get_used_cells ( ) const
Array get_used_cells_by_id ( int id ) const
Rect2 get_used_rect ( )
bool is_cell_transposed ( int x, int y ) const
bool is_cell_x_flipped ( int x, int y ) const
bool is_cell_y_flipped ( int x, int y ) const
bool is_y_sort_mode_enabled ( ) const
Vector2 map_to_world ( Vector2 map_position, bool ignore_half_ofs=false ) const
void set_cell ( int x, int y, int tile, bool flip_x=false, bool flip_y=false, bool transpose=false )
void set_cell_size ( Vector2 size )
void set_cellv ( Vector2 position, int tile, bool flip_x=false, bool flip_y=false, bool transpose=false )
void set_center_x ( bool enable )
void set_center_y ( bool enable )
void set_clip_uv ( bool enable )
void set_collision_bounce ( float value )
void set_collision_friction ( float value )
void set_collision_layer ( int layer )
void set_collision_layer_bit ( int bit, bool value )
void set_collision_mask ( int mask )
void set_collision_mask_bit ( int bit, bool value )
void set_collision_use_kinematic ( bool use_kinematic )
void set_custom_transform ( Transform2D custom_transform )
void set_half_offset ( int half_offset )
void set_mode ( int mode )
void set_occluder_light_mask ( int mask )
void set_quadrant_size ( int size )
void set_tile_origin ( int origin )
void set_tileset ( TileSet tileset )
void set_y_sort_mode ( bool enable )
Vector2 world_to_map ( Vector2 world_position ) const

Signals

  • settings_changed ( )

Emitted when a tilemap setting has changed.

Member Variables

  • bool cell_clip_uv
  • Transform2D cell_custom_transform - The custom Transform2D to be applied to the TileMap’s cells.
  • int cell_half_offset - Amount to offset alternating tiles. Uses HALF_OFFSET_* constants. Default value: HALF_OFFSET_DISABLED.
  • int cell_quadrant_size - The TileMap’s quadrant size. Optimizes drawing by batching, using chunks of this size. Default value: 16.
  • Vector2 cell_size - The TileMap’s cell size.
  • int cell_tile_origin - Position for tile origin. Uses TILE_ORIGIN_* constants. Default value: TILE_ORIGIN_TOP_LEFT.
  • bool cell_y_sort - If true the TileMap’s children will be drawn in order of their Y coordinate. Default value: false.
  • float collision_bounce - Bounce value for static body collisions (see collision_use_kinematic). Default value: 0.
  • float collision_friction - Friction value for static body collisions (see collision_use_kinematic). Default value: 1.
  • int collision_layer - The collision layer(s) for all colliders in the TileMap.
  • int collision_mask - The collision mask(s) for all colliders in the TileMap.
  • bool collision_use_kinematic - If true TileMap collisions will be handled as a kinematic body. If false collisions will be handled as static body. Default value: false.
  • int mode - The TileMap orientation mode. Uses MODE_* constants. Default value: MODE_SQUARE.
  • int occluder_light_mask - The light mask assigned to all light occluders in the TileMap. The TileSet’s light occluders will cast shadows only from Light2D(s) that have the same light mask(s).
  • PoolIntArray tile_data - A PoolIntArray containing
  • TileSet tile_set - The assigned TileSet.

Numeric Constants

  • INVALID_CELL = -1 — Returned when a cell doesn’t exist.
  • MODE_SQUARE = 0 — Orthogonal orientation mode.
  • MODE_ISOMETRIC = 1 — Isometric orientation mode.
  • MODE_CUSTOM = 2 — Custom orientation mode.
  • HALF_OFFSET_X = 0 — Half offset on the X coordinate.
  • HALF_OFFSET_Y = 1 — Half offset on the Y coordinate.
  • HALF_OFFSET_DISABLED = 2 — Half offset disabled.
  • TILE_ORIGIN_TOP_LEFT = 0 — Tile origin at its top-left corner.
  • TILE_ORIGIN_CENTER = 1 — Tile origin at its center.
  • TILE_ORIGIN_BOTTOM_LEFT = 2

Description

Node for 2D tile-based maps. Tilemaps use a TileSet which contain a list of tiles (textures plus optional collision, navigation, and/or occluder shapes) which are used to create grid-based maps.

Member Function Description

  • void clear ( )

Clear all cells.

Return the tile index of the referenced cell.

Return the cell size.

Return the tile index of the cell referenced by a Vector2.

  • bool get_center_x ( ) const

Return true if tiles are to be centered in x coordinate (by default this is false and they are drawn from upper left cell corner).

  • bool get_center_y ( ) const

Return true if tiles are to be centered in y coordinate (by default this is false and they are drawn from upper left cell corner).

  • bool get_clip_uv ( ) const
  • float get_collision_bounce ( ) const

Return the collision bounce parameter.

  • float get_collision_friction ( ) const

Return the collision friction parameter.

  • int get_collision_layer ( ) const

Return the collision layer.

  • bool get_collision_layer_bit ( int bit ) const
  • int get_collision_mask ( ) const

Return the collision mask.

  • bool get_collision_mask_bit ( int bit ) const
  • bool get_collision_use_kinematic ( ) const

Return whether the tilemap handles collisions as a kinematic body.

Return the custom transform matrix.

  • int get_half_offset ( ) const

Return the current half offset configuration.

  • int get_mode ( ) const

Return the orientation mode.

  • int get_occluder_light_mask ( ) const
  • int get_quadrant_size ( ) const

Return the quadrant size.

  • int get_tile_origin ( ) const

Return the tile origin configuration.

Return the current tileset.

  • Array get_used_cells ( ) const

Return an array of all cells containing a tile from the tileset (i.e. a tile index different from -1).

  • Array get_used_cells_by_id ( int id ) const
  • Rect2 get_used_rect ( )

Return whether the referenced cell is transposed, i.e. the X and Y axes are swapped (mirroring with regard to the (1,1) vector).

Return whether the referenced cell is flipped over the X axis.

Return whether the referenced cell is flipped over the Y axis.

  • bool is_y_sort_mode_enabled ( ) const

Return the Y sort mode.

Return the absolute world position corresponding to the tilemap (grid-based) coordinates given as an argument.

Optionally, the tilemap’s potential half offset can be ignored.

Set the tile index for the cell referenced by its grid-based X and Y coordinates.

A tile index of -1 clears the cell.

Optionally, the tile can also be flipped over the X and Y coordinates or transposed.

  • void set_cell_size ( Vector2 size )

Set the cell size.

Set the tile index for the cell referenced by a Vector2 of grid-based coordinates.

A tile index of -1 clears the cell.

Optionally, the tile can also be flipped over the X and Y axes or transposed.

  • void set_center_x ( bool enable )

Set tiles to be centered in x coordinate. (by default this is false and they are drawn from upper left cell corner).

  • void set_center_y ( bool enable )

Set tiles to be centered in y coordinate. (by default this is false and they are drawn from upper left cell corner).

  • void set_clip_uv ( bool enable )
  • void set_collision_bounce ( float value )

Set the collision bounce parameter. Allowable values range from 0 to 1.

  • void set_collision_friction ( float value )

Set the collision friction parameter. Allowable values range from 0 to 1.

  • void set_collision_layer ( int layer )

Set the collision layer.

Layers are referenced by binary indexes, so allowable values to describe the 20 available layers range from 0 to 2^20-1.

  • void set_collision_layer_bit ( int bit, bool value )
  • void set_collision_mask ( int mask )

Set the collision masks.

Masks are referenced by binary indexes, so allowable values to describe the 20 available masks range from 0 to 2^20-1.

  • void set_collision_mask_bit ( int bit, bool value )
  • void set_collision_use_kinematic ( bool use_kinematic )

Set the tilemap to handle collisions as a kinematic body (enabled) or a static body (disabled).

  • void set_custom_transform ( Transform2D custom_transform )

Set custom transform matrix, to use in combination with the custom orientation mode.

  • void set_half_offset ( int half_offset )

Set a half offset on the X coordinate, Y coordinate, or none (use HALF_OFFSET_* constants as argument).

Half offset sets every other tile off by a half tile size in the specified direction.

  • void set_mode ( int mode )

Set the orientation mode as square, isometric or custom (use MODE_* constants as argument).

  • void set_occluder_light_mask ( int mask )
  • void set_quadrant_size ( int size )

Set the quadrant size, this optimizes drawing by batching chunks of map at draw/cull time.

Allowed values are integers ranging from 1 to 128.

  • void set_tile_origin ( int origin )

Set the tile origin to the tile center or its top-left corner (use TILE_ORIGIN_* constants as argument).

  • void set_tileset ( TileSet tileset )

Set the current tileset.

  • void set_y_sort_mode ( bool enable )

Set the Y sort mode. Enabled Y sort mode means that children of the tilemap will be drawn in the order defined by their Y coordinate.

A tile with a higher Y coordinate will therefore be drawn later, potentially covering up the tile(s) above it if its sprite is higher than its cell size.

Return the tilemap (grid-based) coordinates corresponding to the absolute world position given as an argument.