đŸ•šī¸

Godot 2D Platformer Map and Animation

Aug 5, 2024

Tutorial: Creating a Simple Tile Map and Player Animations in Godot

Introduction

  • First tutorial in a series on creating components for a 2D platformer game.
  • Focus on creating a simple tile map with player idle and run animations.
  • Assets used: Warps Caves by Antimos (available for free on itch.io).

Project Setup

  1. Create New Project

    • Project Name: Forward Render
    • Choose folder to save the game.
    • Select "None" for Version Control.
    • Create and Edit project.
  2. Editor Layout

    • Suggested layout:
      • File System on the left
      • History tab next
      • Scene, Import, Inspector, Node, and Main Viewport.
    • Save layout for future use.

Creating a Tile Map

  1. Create 2D Scene

    • Rename scene to "Level" (F2).
    • Add Child Node: TileMap.
  2. Prepare TileSet

    • Create a new folder for TileSet.
    • Import assets from the Warps collection.
    • Locate the tile set PNG file in the assets and drag it into the TileSet folder.
    • Rename TileSet: "Game TileSet 1".
    • Create a new TileSet in the TileMap.
    • Auto-create tiles using the atlas texture.
  3. Configure Tile Map

    • Create a layer named "Ground".
    • Add a Physics layer: Layer 1 is "Ground".
    • Select desired tile and set physics options.
    • Paint the tile onto the map using the rectangle tool.
    • Save the level in a new "Levels" folder.

Creating the Player

  1. Create New 2D Scene for Player

    • Change type to CharacterBody2D.
    • Rename to "Player" and create a folder for Player assets.
    • Save scene in the Player folder.
  2. Add Animated Sprite

    • Add a child node: AnimatedSprite2D.
    • Create new SpriteFrames.
    • Import player idle and run animations from assets.
  3. Configure Animations

    • For Idle Animation:
      • Set frames from sprite sheet.
      • Adjust frames per second and set to loop and auto-load.
    • For Run Animation:
      • Add frames from the run sprite sheet.
      • Adjust frames per second and do not auto-load.

Final Adjustments

  1. Pixel Perfect Display

    • Change Project Settings: Rendering -> Textures -> Default Texture Filter to Nearest.
  2. Positioning Player

    • Adjust Y-position of animated sprite for proper alignment on the X-axis.
    • Add CollisionShape2D to the player and adjust its size.
  3. Physics and Collision Layers

    • Set Player Collision Layer to Layer 2.
    • Ensure player can detect the ground layer collision.

Conclusion

  • End of tutorial.
  • Next tutorial will cover adding player scripts and handling keyboard inputs.
  • Reminder to like and subscribe.
  • Thank you for watching!