From 671c8a7212a275d78052c506f6b92d48e600de53 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sat, 29 Jun 2024 12:48:48 +0200 Subject: [PATCH] ... --- MyObsidianVault/.obsidian/app.json | 3 +- .../M7.L7 - Changing expressions/notes.md | 3 ++ ...us) functions for one-off functionality.md | 6 +++ .../notes.md | 37 +++++++++++++++++++ .../Untitled.md | 0 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L7 - Changing expressions/notes.md create mode 100644 MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/Using lamdba (anonymous) functions for one-off functionality.md create mode 100644 MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/notes.md create mode 100644 MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L9 - Generate buttons at runtime/Untitled.md diff --git a/MyObsidianVault/.obsidian/app.json b/MyObsidianVault/.obsidian/app.json index 058da6b..6ae021d 100644 --- a/MyObsidianVault/.obsidian/app.json +++ b/MyObsidianVault/.obsidian/app.json @@ -7,5 +7,6 @@ "margin": "0", "downscalePercent": 100 }, - "readableLineLength": false + "readableLineLength": false, + "spellcheck": false } \ No newline at end of file diff --git a/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L7 - Changing expressions/notes.md b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L7 - Changing expressions/notes.md new file mode 100644 index 0000000..83594ff --- /dev/null +++ b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L7 - Changing expressions/notes.md @@ -0,0 +1,3 @@ +1. Arrange UI nodes in rows and columns using `Container` nodes. +2. Change the texture of a `TextureRect` node programmatically. +3. Map different image textures to different strings representing the expressions using [dictionaries](https://school.gdquest.com/glossary/dictionary). diff --git a/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/Using lamdba (anonymous) functions for one-off functionality.md b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/Using lamdba (anonymous) functions for one-off functionality.md new file mode 100644 index 0000000..8625929 --- /dev/null +++ b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/Using lamdba (anonymous) functions for one-off functionality.md @@ -0,0 +1,6 @@ +```python + button_sophia.pressed.connect(func() -> void: + body.texture = bodies["sophia"] + ) +``` + diff --git a/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/notes.md b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/notes.md new file mode 100644 index 0000000..80302dd --- /dev/null +++ b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L8 - Code the expression change/notes.md @@ -0,0 +1,37 @@ +In this lesson, you will write the code to change the expressions of the characters when clicking the buttons. + +Loading image at compile time (advantage of seeing error if file doesnt exist) +```python +var image := preload("res:://image.png") +``` + + +Loading at runtime on demand: +```python +load("res:://image.png") +``` + + + + +Preloadingloading into a dictionary: +```python +var bodies := { + "sophia": preload("res://assets/sophia.png"), + "pink": preload("res://assets/pink.png") +} +``` + +Dont forget to multiselect + drag&drop assets into code editor, then multi-cursor correct using +either Alt+Ctrl+Mouseclicks, or Alt+Shift+Cursor Up/Down + + +*Setting TextureRect texture* +```python +func _ready() -> void: + body.texture = bodies["pink"] + expression.texture = expressions["happy"] +``` + + +It's not mandatory to use square brackets to access dictionary values. You can also use the `.` operator. For example, writing `bodies["sophia"]` is equivalent to `bodies.sophia`. \ No newline at end of file diff --git a/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L9 - Generate buttons at runtime/Untitled.md b/MyObsidianVault/Godot_Training/2D/Tutorial Game 4 - Telling a story/M7.L9 - Generate buttons at runtime/Untitled.md new file mode 100644 index 0000000..e69de29