Basic tilemap access setup
parent
220fa9bdcd
commit
baffb6f74a
|
|
@ -1 +1,16 @@
|
||||||
# Game Sprites
|
# Game Sprites
|
||||||
|
|
||||||
|
## Setup and Export
|
||||||
|
|
||||||
|
Tilemap is created using aseprite.
|
||||||
|
Each layer of the tilemap is exported as a separate image using
|
||||||
|
https://github.com/dacap/export-aseprite-file, with some custom changes.
|
||||||
|
Script can be executed from the command line using the batch file
|
||||||
|
[export.bat](../project/assets/tilemap/export.bat).
|
||||||
|
Make sure to have aseprite in the PATH.
|
||||||
|
|
||||||
|
On export, the tileset is automatically updated in godot, making it easy to work with.
|
||||||
|
|
||||||
|
## Sprite/Tilemap list
|
||||||
|
|
||||||
|
TODO (dome)
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,30 +1,30 @@
|
||||||
{
|
{
|
||||||
"width": 320,
|
"height": 320,
|
||||||
"frames": [
|
|
||||||
{
|
|
||||||
"duration": 0.1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
"name": "ground",
|
|
||||||
"cels": [
|
"cels": [
|
||||||
{
|
{
|
||||||
"frame": 0,
|
"frame": 0,
|
||||||
"image": "tilemaps\\tilemap_ground.png"
|
"image": "tilemaps\\tilemap_ground.png"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"name": "ground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "objects",
|
|
||||||
"cels": [
|
"cels": [
|
||||||
{
|
{
|
||||||
"frame": 0,
|
"frame": 0,
|
||||||
"image": "tilemaps\\tilemap_objects.png"
|
"image": "tilemaps\\tilemap_objects.png"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"name": "objects"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"height": 320,
|
"filename": "tilemaps.aseprite",
|
||||||
"filename": "tilemaps.aseprite"
|
"frames": [
|
||||||
|
{
|
||||||
|
"duration": 0.1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"width": 320
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 217 B After Width: | Height: | Size: 313 B |
|
|
@ -6,14 +6,19 @@
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_114re"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_114re"]
|
||||||
texture = ExtResource("1_ukrsa")
|
texture = ExtResource("1_ukrsa")
|
||||||
0:0/0 = 0
|
0:0/0 = 0
|
||||||
|
0:0/0/custom_data_0 = true
|
||||||
1:0/0 = 0
|
1:0/0 = 0
|
||||||
2:0/0 = 0
|
2:0/0 = 0
|
||||||
3:0/0 = 0
|
3:0/0 = 0
|
||||||
|
3:0/0/custom_data_0 = true
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_7jeam"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_7jeam"]
|
||||||
texture = ExtResource("2_o4fdg")
|
texture = ExtResource("2_o4fdg")
|
||||||
0:0/0 = 0
|
0:0/0 = 0
|
||||||
|
1:0/0 = 0
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
|
custom_data_layer_0/name = "walkable"
|
||||||
|
custom_data_layer_0/type = 1
|
||||||
sources/0 = SubResource("TileSetAtlasSource_114re")
|
sources/0 = SubResource("TileSetAtlasSource_114re")
|
||||||
sources/1 = SubResource("TileSetAtlasSource_7jeam")
|
sources/1 = SubResource("TileSetAtlasSource_7jeam")
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,59 @@
|
||||||
|
class_name TileMapLayerAccess
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var tilemap: TileMapLayer = null
|
||||||
|
var sid: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
func setup() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func get_cells_by_type(atlas_coords: Vector2i) -> Array[Vector2i]:
|
||||||
|
return tilemap.get_used_cells_by_id(sid, atlas_coords)
|
||||||
|
|
||||||
|
|
||||||
|
func get_cells_by_custom_data(field_name: String, custom_data: Variant) -> Array[Vector2i]:
|
||||||
|
var tiles_with_custom_data: Array = []
|
||||||
|
for coords in tilemap.get_used_cells():
|
||||||
|
var tile_data: TileData = tilemap.get_cell_tile_data(coords)
|
||||||
|
if tile_data.get_custom_data(field_name) == custom_data:
|
||||||
|
tiles_with_custom_data.append(coords)
|
||||||
|
return tiles_with_custom_data
|
||||||
|
|
||||||
|
|
||||||
|
func get_custom_data(coords: Vector2i, field_name: String) -> Variant:
|
||||||
|
var tile_data: TileData = tilemap.get_cell_tile_data(coords)
|
||||||
|
return tile_data.get_custom_data(field_name)
|
||||||
|
|
||||||
|
|
||||||
|
func get_cells(positions: Array[Vector2i]) -> Array[TileData]:
|
||||||
|
var tiles: Array = []
|
||||||
|
for coords in positions:
|
||||||
|
tiles.append(tilemap.get_cell_tile_data(coords))
|
||||||
|
return tiles
|
||||||
|
|
||||||
|
|
||||||
|
func get_cell(position: Vector2i) -> TileData:
|
||||||
|
return tilemap.get_cell_tile_data(position)
|
||||||
|
|
||||||
|
|
||||||
|
func set_cell(position: Vector2i, atlas_coords: Vector2i) -> void:
|
||||||
|
tilemap.set_cell(position, sid, atlas_coords)
|
||||||
|
|
||||||
|
|
||||||
|
func clear_cell(position: Vector2i) -> void:
|
||||||
|
tilemap.set_cell(position, -1)
|
||||||
|
|
||||||
|
|
||||||
|
func clear_cells() -> void:
|
||||||
|
for coords in tilemap.get_used_cells():
|
||||||
|
tilemap.set_cell(coords, -1)
|
||||||
|
|
||||||
|
|
||||||
|
func local_to_cell(global_position: Vector2) -> Vector2i:
|
||||||
|
return tilemap.local_to_map(global_position)
|
||||||
|
|
||||||
|
|
||||||
|
func cell_to_local(cell_position: Vector2i) -> Vector2:
|
||||||
|
return tilemap.map_to_local(cell_position)
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
class_name TileMapTileTypes
|
||||||
|
|
||||||
|
# ground layer
|
||||||
|
const GRASS: Vector2i = Vector2i(0, 0)
|
||||||
|
const WATER_SHALLOW: Vector2i = Vector2i(1, 0)
|
||||||
|
const WATER_DEEP: Vector2i = Vector2i(2, 0)
|
||||||
|
const SAND: Vector2i = Vector2i(3, 0)
|
||||||
|
|
@ -1,12 +1,33 @@
|
||||||
class_name World
|
class_name World
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
var tilemap_ground: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||||
|
var tilemap_non_interactive: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||||
|
var tilemap_interactive: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||||
|
var tilemap_player: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||||
|
var tilemap_temperature: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||||
|
#
|
||||||
|
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass # Replace with function body.
|
tilemap_ground.tilemap = $GroundLayer
|
||||||
|
tilemap_non_interactive.tilemap = $NonInteractiveObjectsLayer
|
||||||
|
tilemap_interactive.tilemap = $InteractiveObjectsLayer
|
||||||
|
tilemap_player.tilemap = $PlayerLayer
|
||||||
|
tilemap_temperature.tilemap = $TemperatureLayer
|
||||||
|
|
||||||
|
tilemap_ground.setup()
|
||||||
|
tilemap_non_interactive.setup()
|
||||||
|
tilemap_interactive.setup()
|
||||||
|
tilemap_player.setup()
|
||||||
|
tilemap_temperature.setup()
|
||||||
|
|
||||||
|
|
||||||
|
# print(tilemap_non_interactive.get_cells_by_custom_data("walkable", true))
|
||||||
|
# tilemap_ground.clear_cells()
|
||||||
|
# tilemap_ground.set_cell(Vector2i(0, 0), tilemap_types.GRASS)
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
pass
|
print(tilemap_ground.local_to_cell(get_local_mouse_position()))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue