TileMap

    Category: Core

    Node for 2D tile-based maps.

    Properties

    Methods

    void ( )
    voidfix_invalid_tiles ( )
    get_cell ( x, int y ) const
    get_cell_autotile_coord ( x, int y ) const
    get_cellv ( position ) const
    bool ( int bit ) const
    get_collision_mask_bit ( bit ) const
    Array ( ) const
    Array ( int id ) const
    get_used_rect ( )
    is_cell_transposed ( x, int y ) const
    is_cell_x_flipped ( x, int y ) const
    is_cell_y_flipped ( x, int y ) const
    map_to_world ( map_position, bool ignore_half_ofs=false ) const
    void ( int x, y, int tile, flip_x=false, bool flip_y=false, transpose=false, Vector2 autotile_coord=Vector2( 0, 0 ) )
    void ( Vector2 position, tile, bool flip_x=false, flip_y=false, bool transpose=false )
    void ( int bit, value )
    voidset_collision_mask_bit ( bit, bool value )
    void ( Vector2 position )
    void ( Vector2 start=Vector2( 0, 0 ), end=Vector2( 0, 0 ) )
    voidupdate_dirty_quadrants ( )
    world_to_map ( world_position ) const
    • settings_changed ( )

    Emitted when a tilemap setting has changed.

    Enumerations

    enum Mode:

    • MODE_SQUARE = 0 — Orthogonal orientation mode.
    • MODE_ISOMETRIC = 1 — Isometric orientation mode.
    • MODE_CUSTOM = 2 — Custom orientation mode.

    enum HalfOffset:

    • 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.
    • HALF_OFFSET_NEGATIVE_X = 3 — Half offset on the X coordinate (negative).
    • HALF_OFFSET_NEGATIVE_Y = 4 — Half offset on the Y coordinate (negative).

    enum TileOrigin:

    • TILE_ORIGIN_CENTER = 1 — Tile origin at its center.
    • TILE_ORIGIN_BOTTOM_LEFT = 2 — Tile origin at its bottom-left corner.

    Constants

    • INVALID_CELL = -1 — Returned when a cell doesn’t exist.

    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.

    Tutorials

    Property Descriptions

    Setterset_clip_uv(value)
    Getterget_clip_uv()

    • cell_custom_transform
    Setterset_custom_transform(value)
    Getterget_custom_transform()

    The custom Transform2D to be applied to the TileMap’s cells.


    • cell_half_offset
    Setterset_half_offset(value)
    Getterget_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.


    • cell_size
    Setterset_cell_size(value)
    Getterget_cell_size()

    The TileMap’s cell size.


    Setterset_tile_origin(value)
    Getterget_tile_origin()

    Position for tile origin. Uses TILE_ORIGIN_* constants. Default value: TILE_ORIGIN_TOP_LEFT.


    • cell_y_sort
    Setterset_y_sort_mode(value)
    Getteris_y_sort_mode_enabled()

    If , the TileMap’s children will be drawn in order of their Y coordinate. Default value: false.


    Setterset_collision_bounce(value)
    Getterget_collision_bounce()

    Bounce value for static body collisions (see collision_use_kinematic). Default value: 0.


    • collision_friction

    Friction value for static body collisions (see collision_use_kinematic). Default value: 1.


    • int collision_layer
    Setterset_collision_layer(value)
    Getterget_collision_layer()

    The collision layer(s) for all colliders in the TileMap.


    • collision_mask
    Setterset_collision_mask(value)
    Getterget_collision_mask()

    • bool collision_use_kinematic
    Setterset_collision_use_kinematic(value)
    Getterget_collision_use_kinematic()

    If true, TileMap collisions will be handled as a kinematic body. If , collisions will be handled as static body. Default value: false.


    • mode
    Setterset_mode(value)
    Getterget_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).


    • tile_set
    Setterset_tileset(value)
    Getterget_tileset()

    The assigned TileSet.

    Clears all cells.


    • void fix_invalid_tiles ( )

    Clears cells that do not exist in the tileset.


    • get_cell ( int x, y ) const

    Returns the tile index of the given cell. If no tile exists in the cell, returns INVALID_CELL.


    • get_cell_autotile_coord ( int x, y ) const

    • int get_cellv ( position ) const

    Returns the tile index of the cell given by a Vector2. If no tile exists in the cell, returns INVALID_CELL.


    • get_collision_layer_bit ( int bit ) const

    Returns true if the given collision layer bit is set.


    • get_collision_mask_bit ( int bit ) const

    Returns true if the given collision mask bit is set.


    • get_used_cells ( ) const

    Returns a Vector2 array with the positions of all cells containing a tile from the tileset (i.e. a tile index different from -1).


    • get_used_cells_by_id ( int id ) const

    Returns an array of all cells with the given tile id.


    • get_used_rect ( )

    Returns a rectangle enclosing the used (non-empty) tiles of the map.


    • bool is_cell_transposed ( x, int y ) const

    Returns if the given cell is transposed, i.e. the x and y axes are swapped.


    • is_cell_x_flipped ( int x, y ) const

    Returns true if the given cell is flipped in the x axis.


    • bool is_cell_y_flipped ( x, int y ) const

    Returns true if the given cell is flipped in the y axis.


    • map_to_world ( Vector2 map_position, ignore_half_ofs=false ) const

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


    • void set_cell ( int x, y, int tile, flip_x=false, bool flip_y=false, transpose=false, Vector2 autotile_coord=Vector2( 0, 0 ) )

    Sets the tile index for the cell given by a Vector2.

    An index of -1 clears the cell.

    Optionally, the tile can also be flipped, transposed, or given autotile coordinates.

    Note that data such as navigation polygons and collision shapes are not immediately updated for performance reasons.

    If you need these to be immediately updated, you can call .


    • void set_cellv ( Vector2 position, tile, bool flip_x=false, flip_y=false, bool transpose=false )

    Sets the tile index for the given cell.

    An index of -1 clears the cell.

    Optionally, the tile can also be flipped or transposed.

    Note that data such as navigation polygons and collision shapes are not immediately updated for performance reasons.

    If you need these to be immediately updated, you can call .


    • void set_collision_layer_bit ( int bit, value )

    Sets the given collision layer bit.


    • void set_collision_mask_bit ( int bit, value )

    Sets the given collision mask bit.


    • void update_bitmask_area ( Vector2 position )

    Applies autotiling rules to the cell (and its adjacent cells) referenced by its grid-based x and y coordinates.


    • void update_bitmask_region ( start=Vector2( 0, 0 ), Vector2 end=Vector2( 0, 0 ) )

    Applies autotiling rules to the cells in the given region (specified by grid-based x and y coordinates).

    Calling with invalid (or missing) parameters applies autotiling rules for the entire tilemap.



    • world_to_map ( Vector2 world_position ) const

    Returns the tilemap (grid-based) coordinates corresponding to the given local position.