Adding Items
This content is not available in your language yet.
Adding Items
Section titled Adding ItemsNow let’s add a coin pickup.
-
Create a new scene with an Area2D node and rename it Coin.
-
Change the collision mask to only have 2 selected.
-
Give this node a AnimatedSprite2D (rename to AnimatedSprite) and a CollisionShape2D (rename to Collider) as children. Add the coin sprite and animation to the node as before.
-
Give the Collider a New CircleShape2D and have it cover the coin.
-
Attach a script to the Coin node and connect the “body_entered” signal to it. Inside the
_on_body_entered
function make it print something so we can test that it’s working. If you put the coin in your level, it should print out your message when you run over it. To make the coin disappear when you run over it, addqueue_free()
after the print.extends Area2D## Coin that can be picked up, only prints +1 coin## Print +1 coin and free selffunc _on_body_entered(_body: Node2D) -> void:print("+1 coin")queue_free()