SDL3 Oyun Programlama ve Godot Oyun Motoru sayfalarımız yayında...

Ana sayfa > Oyun programlama > Godot game engine > Picking objects

Picking objects

In order to create objects that can be collected by the Player in the game, it is necessary to create a scene in which these objects will be located.

1. To create a new scene, click on the + sign on the right side of the platform tab to create a new Scene.

2. Click on the + sign under the Scene tab or the Ctrl-A key combination to create a new Node.

3. In the Create New Node window that appears, search for Area2D in the Search line and select it, and click the Create button.

We use the Area2d Node when we want to create an area that detects collisions and not collide with other objects. This way, we can detect when a player enters this area.

4. To add graphics, click on the + sign under the Scene tab or press Ctrl-A to create a new Node.

5. In the Create New Node window that appears, search for and select AnimatedSprite2D in the Search line and click on the Create button.

6. While AnimatedSprite2D is selected, under the Animation section of the Inspector tab, select the New SpriteFrames option from the drop-down box on the right side of the Sprite Frames line.

7. A window opens at the bottom of the Godot IDE. Click on the Add frames from Sprite Sheet button in this window.

8. In the first window that opens, enter the assets/sprites directory and open the coin.png file in the directory in the second window.

9. Edit the window that opens as follows and click the "Add 12 Frames" button.

10. Make the following adjustments.

  • Set the FPS value to 10.
  • Click the Loop and AutoPlay buttons.
  • Run the animation with the Run button.

11. To define a Collision Shape for the Area2d Node, create a new Node by clicking the + sign under the Scene tab or by pressing the Ctrl-A key combination while the "Area2d" Node is selected.

12. In the Create New Node window that appears, search for and select the expression CollisionShape2D in the Search line and click on the Create button.

13. While "CollisionShape2D" is selected, in the "Inspector" tab, select the "New CircleShape2D" option from the selection box to the right of the "Shape" line. Reduce the circle size created in the scene to the width of the image and align it below it.

14. Change the "Area2d" Node name to "Coin" and save it as "scenes\coin.tscn" file by pressing Ctrl-S.

15. While the "game" Scene is selected, drag and drop the "coin.tsn" file 9 times onto the stage.

Save the "game" scene with Ctrl-S. When we run the game, no action takes place when the Player enters the coins' area. In order for an action to take place, a script must be added for the Coin Node.