From 7fdad57d8bb123441f5053d620f73dd5a8394c35 Mon Sep 17 00:00:00 2001 From: ronny abraham Date: Wed, 13 Nov 2024 02:58:06 +0200 Subject: [PATCH] added notes --- _subsections/sec03/lesson-07.org | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/_subsections/sec03/lesson-07.org b/_subsections/sec03/lesson-07.org index 6730e05..0d15722 100644 --- a/_subsections/sec03/lesson-07.org +++ b/_subsections/sec03/lesson-07.org @@ -1,3 +1,5 @@ +#+HTML_HEAD: +#+HTML_HEAD: #+title: Section 03 - Lesson 07 | Moving the Gem * Links @@ -5,3 +7,89 @@ - [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070467#announcements][S03:L14.07 - Moving the Gem]] * Notes + +we use scripting to extend node functionality + +** get the gem to fall +- we need to get the Gem/Area2D node to fall + - if we had the sprite fall, the collision2D node would stay where it was + + +*** add a script to the root node + - click on the attach new script button in the scene pane + - + #+ATTR_HTML: :width 200px + [[file:../../../_share/media/img/albert/attach_new_script.png]] + - one script per node is the limit + - you get access to all the children nodes inside the scene. + +*** attach node script dialogue +- Template is generally Node: Default +- some object types provide other templates with different boiler plate code + +- the node we attached a script to will have a script icon next to the eye icon + - + #+ATTR_HTML: :width 200px + [[file:../../../_share/media/img/albert/script_icon.png]] + +*** detaching script from node +- sometimes you don't want a certain script attached to a node + - for testing purposes to prevent a script from doing something + - you want a different script, etc. + +- if a script is attached, then when you select the node the "script attach button" will change from a green plus to a red x +- press the button and detach it + +** life cycle of a node +*** functions +- _ready() +- _process(delta:float) + +*** tree build by stages +1. initialization stage + - creation + - function: _init_() + +2. attachment stage + - added to tree + - function: _enter_tree() + +3. finalization stage + - node and children ready + - function: _read() + +*** how it is built +- every node is given an id before it gets a name + +- all init functions will be called before any other stage for any other node is invoked + +- similarly the attachment stage, of adding nodes to other nodes takes place before any other function in any other node is activated + - at this point we get a name for the node + +- ready tells us that the node is up and ready to go, and so are its children + - therefore the children of the node will be set up before the parent + - ready will be called for the children first + +*** process functions +- invoked on all nodes +- every frame + +- used to update the node each frame + +- delta refers to the time that elapsed since previous call on previous frame + - use delta to normalize things + +**** _process(delta) +- called in main loop +- as fast as possible + +**** _physics_process(delta) +- called in main loop +- regular interval + +** adding code to move gem down +- increase the y position +- all node parameters can be found in inspector (including inherited) +- position.y = position.y + speed * delta + - speed can be anything + - we multiply by delta to normalize it compared to the time of the previous frame