From 3a4b1cea9b9602d96712b504b13d81cc4e39cd6a Mon Sep 17 00:00:00 2001 From: Torsten Date: Sat, 31 May 2025 11:18:33 +0200 Subject: [PATCH] ... --- .../Use Tile from Atlas for UI TextureRect.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 MyObsidianVault/Knowledgebase/Godot/2D/Use Tile from Atlas for UI TextureRect.md diff --git a/MyObsidianVault/Knowledgebase/Godot/2D/Use Tile from Atlas for UI TextureRect.md b/MyObsidianVault/Knowledgebase/Godot/2D/Use Tile from Atlas for UI TextureRect.md new file mode 100644 index 0000000..e4901c8 --- /dev/null +++ b/MyObsidianVault/Knowledgebase/Godot/2D/Use Tile from Atlas for UI TextureRect.md @@ -0,0 +1,21 @@ +```python +extends Node2D + +@onready var main: Node2D = $"." +@onready var palette: VBoxContainer = $UI/PanelContainer/ScrollContainer/VBoxContainer + +func _ready(): + print("Palette initialized.") + + var atlas_texture = AtlasTexture.new() + var atlas_image = Image.new() + + atlas_image.load("res://assets/spritesheets/map_hex_terrain_72x72_spritesheet.png") + atlas_texture.atlas = ImageTexture.create_from_image(atlas_image) + atlas_texture.region = Rect2(Vector2(0,73),Vector2(72,72)) # x,y,width,height + + var tr = TextureRect.new() + tr.texture = atlas_texture + + palette.add_child(tr) +```