added remove gem

This commit is contained in:
ronny abraham 2024-11-14 03:16:25 +02:00
parent 7fdad57d8b
commit 2fcf9caf48

View file

@ -1,21 +1,24 @@
#+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/org-mode.css" />
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../_share/media/css/godot.css" /> #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../_share/media/css/godot.css" />
#+title: Section 03 - Lesson 07 | Moving the Gem #+title: Section 03 - Lesson 07, 09 | Moving/ Removing the Gem
* Links * Links
- [[../../toc.org][TOC - Godot Notes]] - [[../../toc.org][TOC - Godot Notes]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070467#announcements][S03:L14.07 - Moving the Gem]] - [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070467#announcements][S03:L15.07 - Moving the Gem]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070471#announcements][S03:L15.09 - Removing the Gem]]
* Notes * Notes
** Moving the Gem
we use scripting to extend node functionality we use scripting to extend node functionality
** get the gem to fall *** get the gem to fall
- we need to get the Gem/Area2D node 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 - if we had the sprite fall, the collision2D node would stay where it was
*** add a script to the root node **** add a script to the root node
- click on the attach new script button in the scene pane - click on the attach new script button in the scene pane
- -
#+ATTR_HTML: :width 200px #+ATTR_HTML: :width 200px
@ -23,7 +26,7 @@ we use scripting to extend node functionality
- one script per node is the limit - one script per node is the limit
- you get access to all the children nodes inside the scene. - you get access to all the children nodes inside the scene.
*** attach node script dialogue **** attach node script dialogue
- Template is generally Node: Default - Template is generally Node: Default
- some object types provide other templates with different boiler plate code - some object types provide other templates with different boiler plate code
@ -32,7 +35,7 @@ we use scripting to extend node functionality
#+ATTR_HTML: :width 200px #+ATTR_HTML: :width 200px
[[file:../../../_share/media/img/albert/script_icon.png]] [[file:../../../_share/media/img/albert/script_icon.png]]
*** detaching script from node **** detaching script from node
- sometimes you don't want a certain script attached to a node - sometimes you don't want a certain script attached to a node
- for testing purposes to prevent a script from doing something - for testing purposes to prevent a script from doing something
- you want a different script, etc. - you want a different script, etc.
@ -40,12 +43,12 @@ we use scripting to extend node functionality
- 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 - 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 - press the button and detach it
** life cycle of a node *** life cycle of a node
*** functions **** functions
- _ready() - _ready()
- _process(delta:float) - _process(delta:float)
*** tree build by stages **** tree build by stages
1. initialization stage 1. initialization stage
- creation - creation
- function: _init_() - function: _init_()
@ -58,7 +61,7 @@ we use scripting to extend node functionality
- node and children ready - node and children ready
- function: _read() - function: _read()
*** how it is built **** how it is built
- every node is given an id before it gets a name - 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 - all init functions will be called before any other stage for any other node is invoked
@ -70,7 +73,7 @@ we use scripting to extend node functionality
- therefore the children of the node will be set up before the parent - therefore the children of the node will be set up before the parent
- ready will be called for the children first - ready will be called for the children first
*** process functions **** process functions
- invoked on all nodes - invoked on all nodes
- every frame - every frame
@ -87,9 +90,21 @@ we use scripting to extend node functionality
- called in main loop - called in main loop
- regular interval - regular interval
** adding code to move gem down *** adding code to move gem down
- increase the y position - increase the y position
- all node parameters can be found in inspector (including inherited) - all node parameters can be found in inspector (including inherited)
- position.y = position.y + speed * delta - position.y = position.y + speed * delta
- speed can be anything - speed can be anything
- we multiply by delta to normalize it compared to the time of the previous frame - we multiply by delta to normalize it compared to the time of the previous frame
** Removing the Gem
*** basic idea
- use the viewport rect
- find the height of the rect
- when the y position of the gem is outside the bounds remove it
*** implementation
- use get_viewport_rect to get the w,h
- check if position.y > rect.size.y
- use queue_free function to remove this from the queue
- set process to stop being called via set_process