Character scene

Start creating the Character scene by adding an Area2D and naming it Character. Area2D is a good choice for this type of character because its main function will be to detect overlaps—when it moves onto an item or enemy, for example.

Add the following children:

  • Sprite
  • CollisionShape2D
  • Tween (named MoveTween)
  • AnimationPlayer

Leave the Sprite without a texture, but in the Inspector, under the Animation section of the Sprite, set its Vframes and Hframes properties to 4 and 5, respectively. This tells Godot to slice the texture into a 5 x 4 grid of inpidual images.

The spritesheets you'll use for the player and the enemy are arranged in exactly this pattern, with each row containing the animation frames for a single direction of movement:

When a spritesheet has been sliced using the Vframes and Hframes properties, you can use the Frame property to set which inpidual frame to use. In the preceding player sheet, the left-facing animation would use frames 5 through 9 (counting from frame 0 in the upper-left corner). You'll use an AnimationPlayer to change the Frame property below. Refer to the following screenshot:

Next, create a new RectangleShape2D in the collision shape's Shape. Click on the new <RectangleShape2D> and set its Extents property in the Inspector to (16, 16). Note that Extents measures the distance from the center in each direction, so this results in a collision shape that is 32 by 32 pixels.

Because all the characters are drawn to the same scale, we can be confident that the same sized collision shape will work for all characters. If this isn’t the case with the art you’re using, you can skip setting the collision shape here and configure it later for the inpidual inherited scenes.