Collectible scene
Start the new scene with an Area2D and name it Collectible. An area is a good choice for these objects because you want to detect when the player contacts them (using the body_entered signal), but you don't need collision response from them. In the Inspector, set the Collision/Layer to collectibles (layer 4) and the Collision/Mask to player (layer 2). This will ensure that only the Player node will be able to collect an item while the enemies will pass right through.
Add three child nodes: Sprite, CollisionShape2D, and AnimationPlayer, then drag the res://assets/cherry.png Sprite sheet into the Sprite's Texture. Set the Vframes to 1 and Hframes to 5. Add a rectangle shape to CollisionShape2D and size it appropriately.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access