compsci_godot_albert/_subsections/sec03/lesson-13.org

71 lines
2.1 KiB
Org Mode
Raw Normal View History

2024-11-27 04:24:34 +02:00
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../../../../_share/media/css/org-mode.css" />
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />
2024-11-20 03:28:17 +02:00
#+title: Section 03 - Lesson 13, 14 | Spawn Timer, Spawning gems
2024-11-16 22:05:19 +02:00
* Links
- [[../../toc.org][TOC - Godot Notes]]
2024-11-20 03:28:17 +02:00
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070483#announcements][S03:L24.13 - Spawn Timer]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070485#announcements][S03:L25.14 - Spawning Gems]]
2024-11-16 22:05:19 +02:00
* Notes
2024-11-20 03:28:17 +02:00
** removing connected nodes
- nodes that are connected must be disconnected before deletion
- otherwise strange things happen
** Timing
- add a child node
- search for Timer
*** properties
- autostart: whether it starts as soon as scene is ready in tree
- one shot: time once and stop
- wait time: the actual time it goes
*** signals
- timeout
- got to Inspector->Node
- timeout emits a signal when the wait time hits zero
** Spawning Gems
Put the following in the script that you want to create nodes in based on a scene:
#+BEGIN_SRC gdscript
@export var gem_scene: PackedScene
#+END_SRC
*** terms
- =@export=
- makes the variable accessible and modifiable from the Godot editor
- allows assigning variables through the interface
#+ATTR_HTML: :width 300px
2024-11-24 03:50:33 +02:00
[[file:../../../_share/media/albert/img/section03/S03_L14_EX01.png]]
2024-11-20 03:28:17 +02:00
- =PackedScene=
- resource that holds a scene in a packed, ready to load state
*** what it does
allows us to create instances of the scene
- drag a scene into the property in the inspector
- call instance
#+BEGIN_SRC gdscript
func spawn_gem() -> void:
var gem_instance = gem_scene.instance()
add_child(gem_instance)
#+END_SRC
** how to explicitly assign the type of a custom script
- in the script near the top type in
#+BEGIN_SRC gdscript
class_name CustomName
#+END_SRC
- then override on assigning the value
#+BEGIN_SRC gdscript
var new_gem: CustomName = gem_scene.instantiate()
#+END_SRC