跳转至

TileMap

继承

Node2D

简要描述

基于2D切片的地图的节点。

描述

基于2D切片的地图的节点。 Tilemap使用TileSet,其中包含用于创建基于网格的地图的图块列表(纹理以及可选的碰撞,导航和/或遮挡物形状)。

成员

类型 属性名 默认值
bool cell_clip_uv false
Transform2D cell_custom_transform Transform2D( 64, 0, 0, 64, 0, 0 )
int cell_half_offset 2
int cell_quadrant_size 16
Vector2 cell_size Vector2( 64, 64 )
int cell_tile_origin 0
bool cell_y_sort false
bool centered_textures false
float collision_bounce 0.0
float collision_friction 1.0
int collision_layer 1
int collision_mask 1
bool collision_use_kinematic false
bool collision_use_parent false
bool compatibility_mode false
int mode 0
int occluder_light_mask 1
TileSet tile_set

方法

返回值类型 方法名称
void clear()
void fix_invalid_tiles()
int get_cell(x: int, y: int) const
Vector2 get_cell_autotile_coord(x: int, y: int) const
int get_cellv(position: Vector2) const
bool get_collision_layer_bit(bit: int) const
bool get_collision_mask_bit(bit: int) const
Array get_used_cells() const
Array get_used_cells_by_id(id: int) const
Rect2 get_used_rect()
bool is_cell_transposed(x: int, y: int) const
bool is_cell_x_flipped(x: int, y: int) const
bool is_cell_y_flipped(x: int, y: int) const
Vector2 map_to_world(map_position: Vector2, ignore_half_ofs: bool = false) const
void set_cell(x: int, y: int, tile: int, flip_x: bool = false, flip_y: bool = false, transpose: bool = false, autotile_coord: Vector2 = Vector2( 0, 0 ))
void set_cellv(position: Vector2, tile: int, flip_x: bool = false, flip_y: bool = false, transpose: bool = false)
void set_collision_layer_bit(bit: int, value: bool)
void set_collision_mask_bit(bit: int, value: bool)
void update_bitmask_area(position: Vector2)
void update_bitmask_region(start: Vector2 = Vector2( 0, 0 ), end: Vector2 = Vector2( 0, 0 ))
void update_dirty_quadrants()
Vector2 world_to_map(world_position: Vector2) const

信号

  • settings_changed

当Tilemap设置更改时发出。


枚举

enum Mode: - MODE_SQUARE = 0

正交方向模式。

  • MODE_ISOMETRIC = 1

等距定向模式。

  • MODE_CUSTOM = 2

自定义方向模式。


enum HalfOffset: - HALF_OFFSET_X = 0

X坐标上的一半偏移。

  • HALF_OFFSET_Y = 1

Y坐标上的一半偏移量。

  • HALF_OFFSET_DISABLED = 2

半偏移量禁用。

  • HALF_OFFSET_NEGATIVE_X = 3

X坐标的一半偏移(负)。

  • HALF_OFFSET_NEGATIVE_Y = 4

Y坐标的一半偏移(负)。


enum TileOrigin: - TILE_ORIGIN_TOP_LEFT = 0

在其左上角平铺原点。

  • TILE_ORIGIN_CENTER = 1

图块原点位于其中心。

  • TILE_ORIGIN_BOTTOM_LEFT = 2

在其左下角平铺原点。


常量

  • INVALID_CELL = -1

当一个单元格不存在时返回。

成员说明

  • bool cell_clip_uv
Default false
setter set_clip_uv(value)
getter get_clip_uv
  • Transform2D cell_custom_transform
Default Transform2D( 64, 0, 0, 64, 0, 0 )
setter set_custom_transform(value)
getter get_custom_transform
  • int cell_half_offset
Default 2
setter set_half_offset(value)
getter get_half_offset
  • int cell_quadrant_size
Default 16
setter set_quadrant_size(value)
getter get_quadrant_size
  • Vector2 cell_size
Default Vector2( 64, 64 )
setter set_cell_size(value)
getter get_cell_size
  • int cell_tile_origin
Default 0
setter set_tile_origin(value)
getter get_tile_origin
  • bool cell_y_sort
Default false
setter set_y_sort_mode(value)
getter is_y_sort_mode_enabled
  • bool centered_textures
Default false
setter set_centered_textures(value)
getter is_centered_textures_enabled
  • float collision_bounce
Default 0.0
setter set_collision_bounce(value)
getter get_collision_bounce
  • float collision_friction
Default 1.0
setter set_collision_friction(value)
getter get_collision_friction
  • int collision_layer
Default 1
setter set_collision_layer(value)
getter get_collision_layer
  • int collision_mask
Default 1
setter set_collision_mask(value)
getter get_collision_mask
  • bool collision_use_kinematic
Default false
setter set_collision_use_kinematic(value)
getter get_collision_use_kinematic
  • bool collision_use_parent
Default false
setter set_collision_use_parent(value)
getter get_collision_use_parent
  • bool compatibility_mode
Default false
setter set_compatibility_mode(value)
getter is_compatibility_mode_enabled
  • int mode
Default 0
setter set_mode(value)
getter get_mode
  • int occluder_light_mask
Default 1
setter set_occluder_light_mask(value)
getter get_occluder_light_mask
  • TileSet tile_set
setter set_tileset(value)
getter get_tileset

方法说明

  • clear clear()

清除所有单元格。


  • fix_invalid_tiles fix_invalid_tiles()

清除图块集中不存在的单元格。


  • get_cell get_cell(x: int, y: int) const

返回给定单元格的图块索引。如果单元格中没有图块,则返回INVALID_CELL


  • get_cell_autotile_coord get_cell_autotile_coord(x: int, y: int) const

返回图块集中自动变形的坐标。如果单元格没有自动倾斜,则返回一个零向量。


  • get_cellv get_cellv(position: Vector2) const

返回Vector2给定的单元格的图块索引。如果单元格中没有图块,则返回INVALID_CELL


  • get_collision_layer_bit get_collision_layer_bit(bit: int) const

如果设置了给定的碰撞层位,则返回true


  • get_collision_mask_bit get_collision_mask_bit(bit: int) const

如果设置了给定的碰撞掩码位,则返回true


  • get_used_cells get_used_cells() const

返回一个Vector2数组,其中包含该图块集中包含图块的所有单元的位置(即,与-1不同的图块索引)。


  • get_used_cells_by_id get_used_cells_by_id(id: int) const

返回具有给定图块id的所有单元格的数组。


  • get_used_rect get_used_rect()

返回一个矩形,其中包含地图的已使用(非空)图块。


  • is_cell_transposed is_cell_transposed(x: int, y: int) const

如果给定单元格已换位,即X和Y轴已交换,则返回true


  • is_cell_x_flipped is_cell_x_flipped(x: int, y: int) const

如果给定的单元格在X轴上翻转,则返回true


  • is_cell_y_flipped is_cell_y_flipped(x: int, y: int) const

如果给定的单元格在Y轴上翻转,则返回true


  • map_to_world map_to_world(map_position: Vector2, ignore_half_ofs: bool = false) const

返回与给定的Tilemap(基于网格)坐标相对应的全局位置。

(可选)可以忽略Tilemap的一半偏移量。


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

设置由Vector2给定的单元格的图块索引。

索引为-1的单元格将被清除。

可选地,图块也可以翻转,转置或给定自动坐标。

**注意:**由于性能原因,导航多边形和碰撞形状之类的数据不会立即更新。

如果需要立即更新它们,可以调用update_dirty_quadrants

覆盖此方法还将在内部覆盖此方法,从而允许在放置/移除图块时实现自定义逻辑:

func set_cell(x, y, tile, flip_x, flip_y, transpose, autotile_coord)
    # Write your custom logic here.
    # To call the default method:
    .set_cell(x, y, tile, flip_x, flip_y, transpose, autotile_coord)

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

设置给定单元格的图块索引。

索引为-1的单元格将被清除。

可选地,瓦片也可以被翻转或转置。

**注意:**由于性能原因,导航多边形和碰撞形状之类的数据不会立即更新。

如果需要立即更新它们,可以调用update_dirty_quadrants


  • set_collision_layer_bit set_collision_layer_bit(bit: int, value: bool)

设置给定的碰撞层位。


  • set_collision_mask_bit set_collision_mask_bit(bit: int, value: bool)

设置给定的碰撞掩码位。


  • update_bitmask_area update_bitmask_area(position: Vector2)

将自动调整规则应用于由基于网格的X和Y坐标引用的单元格(及其相邻单元格)。


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

将自动倾斜规则应用于给定区域中的单元格(由基于网格的X和Y坐标指定)。

使用无效(或丢失)参数的调用将对整个Tilemap应用自动倾斜规则。


  • update_dirty_quadrants update_dirty_quadrants()

更新图块地图的象限,如果进行修改,则可以立即使用导航和碰撞形状之类的东西。


  • world_to_map world_to_map(world_position: Vector2) const

返回对应于给定本地位置的Tilemap(基于网格)坐标。