Базовое редактирование тайлов

This commit is contained in:
DIvan2000 2024-12-06 02:50:32 +04:00
parent 993953df4f
commit ce242e4f6d
8 changed files with 686 additions and 4 deletions

View File

Before

Width:  |  Height:  |  Size: 994 B

After

Width:  |  Height:  |  Size: 994 B

View File

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://qmjuy68vr7jp" uid="uid://qmjuy68vr7jp"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" path="res://.godot/imported/icon.svg-56083ea2a1f1a4f1e49773bdc6d7826c.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://icon.svg" source_file="res://assets/icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] dest_files=["res://.godot/imported/icon.svg-56083ea2a1f1a4f1e49773bdc6d7826c.ctex"]
[params] [params]

BIN
assets/tileset.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

34
assets/tileset.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://hksnxmrpo2cp"
path="res://.godot/imported/tileset.png-c50288acd069fa293d7940a084811264.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/tileset.png"
dest_files=["res://.godot/imported/tileset.png-c50288acd069fa293d7940a084811264.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -11,8 +11,9 @@ config_version=5
[application] [application]
config/name="TestProject" config/name="TestProject"
run/main_scene="res://world.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility") config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://assets/icon.svg"
[dotnet] [dotnet]

11
tile_map_layer.gd Normal file
View File

@ -0,0 +1,11 @@
extends TileMapLayer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

22
world.gd Normal file
View File

@ -0,0 +1,22 @@
extends Node2D
# Переменная для хранения ссылки на TileMap
@onready var tilemap: TileMapLayer = $TileMapLayer
var is_drawing: bool = false # Флаг для отслеживания зажатия кнопки мыши
func _ready():
pass
func _input(event):
if event is InputEventMouseButton:
# Проверяем нажатие или отпускание левой кнопки мыши
if event.button_index == MOUSE_BUTTON_LEFT:
is_drawing = event.pressed # Устанавливаем флаг, если кнопка нажата
if event is InputEventMouseMotion and is_drawing:
# Получаем позицию мыши в мировых координатах
var current_tile:Vector2 = tilemap.local_to_map(get_global_mouse_position()-tilemap.global_position)
var tile_pos = tilemap.map_to_local(current_tile)
tilemap.set_cells_terrain_connect([current_tile], 0, 2, true)
# Преобразуем в координаты тайлов
# Устанавливаем тайл (tile_id = 1 в данном случае)

614
world.tscn Normal file

File diff suppressed because one or more lines are too long