compsci_godot_albert/_subsections/sec03/lesson-03.org
2024-11-27 04:24:34 +02:00

2.1 KiB

Section 03 - Lesson 03 | Paddle Scene

Notes

scenes

there are three basic scenes we are going to create

  1. Gem Scene

    • Sprite2D
    • CollisionShape2D
  2. Paddle Scene

    • Sprite2D
    • CollisionShape2D
  3. Game Scene

    • Sprite2D
    • Paddle Scene
    • Timer
    • ScoreLabel
    • AudioStreamPLayer2D
    • AudioStreamPlayer

creating a new scene

  1. go to the top of the center pane, and click on the plus.

    • this creates an empty unsaved scene
    • you must create a new root node.

      • click the '+' symbol in the upper left scene pane
      • search for Area2D: "a region of 2D space that detects other CollesionObject2Ds enteriinig or exiting it"
  2. Menu->Scene->New Scene

    • select a root node, ie 2DScene - which will set your root node as a Node2D
    • or create one via the "+"

using a Area2D root node

  • you must add a shape so the root node can interact with other objects and detect collisions or overlaps

    • CollisionShape2D
    • CollisionPolygon2D

add collisoinshape2D

  • "+" -> CollisionShape2D
  • add a shape

    • CollsionsShape2D node -> Inspector -> CollisionShape2D -> Shape -> <choose from dropdown>

add sprite2D

  • the shape is only for background processing
  • "+" -> Sprite2D
  • drag and drop an image into Inspector->Sprite2D->Texture

refitting the collision shape

  • currently the collision shape is being drawn first, then the sprite on top of it
  • reorder so that the sprite gets drawn first, then the colision shape
  • resize the collision shape, use transform if you need to

add paddle to game scene

  • go to the game scene
  • click the chain button in the upper left scene pain, the chain button is to the right of the "+"
  • select which scene you want to add