Grid finally working and understood
This commit is contained in:
@@ -18,6 +18,9 @@ var _MovingMarker: Node2D = _MovingMarkerScene.instantiate()
|
||||
|
||||
@onready var GroundLayer: TileMapLayer = $Map/Ground
|
||||
|
||||
var aStarGrid: AStarGrid2D:
|
||||
set(v): aStarGrid = v;
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# add_child(_MovingMarker)
|
||||
@@ -26,7 +29,7 @@ func _ready() -> void:
|
||||
# create unit at local position (50, 50) => eg mouse position
|
||||
_createUnit(GroundLayer.local_to_map(Vector2i(50, 50)))
|
||||
# create unit at map position (50, 50) => tile x = 50, y = 50 in the map
|
||||
_createUnit(GroundLayer.map_to_local(Vector2i(50,50)))
|
||||
_createUnit(GroundLayer.map_to_local(Vector2i(25,25)))
|
||||
|
||||
for unit in _Units:
|
||||
add_child(unit)
|
||||
@@ -36,9 +39,6 @@ func _ready() -> void:
|
||||
# if firstUnit.is_node_ready():
|
||||
# UnitCamera.target = _Units[0].get_path_to(get_parent())
|
||||
# UnitCamera.target_node = _Units[0]
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
@@ -63,3 +63,20 @@ func _getScreenCenter():
|
||||
|
||||
func _getMousePosition(event: InputEvent):
|
||||
return get_viewport().get_camera_2d().make_input_local(event)
|
||||
|
||||
|
||||
#func prepareAStarGrid():
|
||||
# var astarGrid = AStarGrid2D.new()
|
||||
# astarGrid.cell_size = GroundLayer.tile_set.tile_size
|
||||
# astarGrid.region = Rect2(Vector2.ZERO, ceil(get_viewport_rect().size / astarGrid.cell_size))
|
||||
# astarGrid.update()
|
||||
#
|
||||
# for id in ObstacleLayer.get_used_cells():
|
||||
# var data: TileData = ObstacleLayer.get_cell_tile_data(id)
|
||||
# if data and data.get_custom_data('obstacle'):
|
||||
# astarGrid.set_point_solid(id)
|
||||
#
|
||||
# %GridDisplay.grid = astarGrid
|
||||
|
||||
func get_cell_information(cell):
|
||||
print(cell)
|
||||
|
||||
Reference in New Issue
Block a user