...
This commit is contained in:
parent
408e127da2
commit
671c8a7212
5 changed files with 48 additions and 1 deletions
3
MyObsidianVault/.obsidian/app.json
vendored
3
MyObsidianVault/.obsidian/app.json
vendored
|
|
@ -7,5 +7,6 @@
|
||||||
"margin": "0",
|
"margin": "0",
|
||||||
"downscalePercent": 100
|
"downscalePercent": 100
|
||||||
},
|
},
|
||||||
"readableLineLength": false
|
"readableLineLength": false,
|
||||||
|
"spellcheck": false
|
||||||
}
|
}
|
||||||
|
|
@ -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).
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
```python
|
||||||
|
button_sophia.pressed.connect(func() -> void:
|
||||||
|
body.texture = bodies["sophia"]
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
@ -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`.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue