Collectible items
Before you start making the level, you need to create some items that the player can collect, since those will be part of the level as well. The assets/sprites
folder contains sprite sheets for two types of collectibles: cherries and gems.
Rather than make a separate scene for each type of item, you can use a single scene and swap out the texture
property in the script. Both objects have the same behavior: animating in place and disappearing when collected by the player. You can also add a tween
effect for the collection (see Chapter 2).
Scene setup
Start the new scene with Area2D
and name it Item
. Save the scene in a new items
folder.
An area is a good choice for these objects because you want to detect when the player contacts them, but you don’t need a collision response from them. In the Inspector, set Collision/Layer to collectibles
(layer 4) and Collision/Mask to player
(layer 2). This will ensure that only the Player
node will be able to...