Putting our Player object in its own scene will allow us to test it before we finish the whole game! In general, it is a good idea to have the root node reflect the main functionality of the object or what the object is. In this case, we will create a new Area2D node as our root node and rename it Player! You may see a warning icon pop up and that is okay. We will fix that problem soon enough.
Before we begin adding any children node, we should make sure that none of its children are selectable. See the following picture to find the correct button:
During our work today, we will want to save frequently. You can either do this by clicking Scene in the main menu and clicking save or by pressing Ctrl+S or Cmd+S.
The first child node we want to add to the Player node is an AnimatedSprite node! This will handle the appearance and animations for our player character. After we have added the new node, we will go to the inspector window and find the Frames property. Inside this property, we want to change “[empty]” to “New SpriteFrames.” Once you have done that, you should click again to open the “SpriteFrames” panel which will look like this:
First, we want to click default and change it to say “walk”. Next, we will create a new animation and name it “up”. After you have done this, you can drag in the respective images from our resource folder. This will cause the “walk” animation panel to look something like below:
You might now see your player character on the screen. We first want to click and drag it into the middle of our play area so that we have a good starting point. Right now it is a little large. To fix this, we will need to click the AnimatedSprite node and change the Scale property to (0.5, 0.5) under the Node2D heading.
Finally, we need to add a CollisionShape2D as a child of Player. This will help to determine our player’s hitbox. Now your scene tree should look like this:
Lastly, we will need to give our CollisionShape2D a shape. Simply change the Shape property in the Inspector pane to “New CapsuleShape2D” and resize it using the handles so that it covers the sprite!