Skip to main content

Introduction

Godot provides a comprehensive 2D engine for creating games and applications. All 2D nodes inherit from Node2D, which provides a transform system for position, rotation, scale, and skew.

The 2D Coordinate System

Godot uses a right-handed 2D coordinate system:
  • X-axis: Points to the right (positive values)
  • Y-axis: Points downward (positive values)
  • Origin: Top-left corner at (0, 0)
Unlike some engines where Y points upward, Godot’s Y-axis points down. This matches screen coordinate conventions.

Node2D Base Class

The Node2D class is the foundation for all 2D objects. It provides transformation properties and methods for positioning and orienting nodes in 2D space.

Transform Properties

Global Transform Properties

Every transform property has a global equivalent:
  • global_position
  • global_rotation / global_rotation_degrees
  • global_scale
  • global_skew
  • global_transform

Basic Movement

Transform Methods

Coordinate Conversion

Convert between local and global coordinates:

Z-Index and Draw Order

The z_index property (inherited from CanvasItem) controls draw order:
Nodes with higher z_index values are drawn on top. Within the same z_index, nodes are drawn in tree order.

Y-Sorting

For top-down games, enable Y-sorting to automatically order nodes by their Y position:

2D Cameras

The Camera2D node controls what portion of the 2D scene is visible.

Basic Camera Setup

Camera Following

Attach a Camera2D as a child of the player node to follow them:

Camera Limits

Constrain camera movement to level boundaries:

Camera Smoothing

Add smooth camera movement:

Drag Margins

Create a dead-zone where the player can move without moving the camera:

Camera Shake

2D Lighting

Godot provides 2D lighting nodes for creating dynamic lighting effects in 2D games.

Light Types

PointLight2D - Emits light in all directions from a point:
DirectionalLight2D - Directional light source (like sunlight):

Light Modes

Lights can use different blend modes:
  • Add - Adds light (default)
  • Sub - Subtracts light (creates shadows)
  • Mix - Mixes with existing lighting

Shadows

Enable shadows with the shadow_enabled property. Configure shadow properties:
Use LightOccluder2D nodes with appropriate shapes to create shadows from sprites and world geometry.

Transform Hierarchy

Transforms are hierarchical. A child node’s transform is relative to its parent:

Best Practices

When moving nodes relative to their parent, use local transform properties like position and rotate().
For world-space positioning (like spawning projectiles), use global_position.
Attach the camera to the player for simple following. Use a separate camera node with scripting for more complex behavior.
Remember that negative Y values move upward: velocity.y = -500 for jumping.

Next Steps

Sprites and Textures

Learn how to display and animate sprites

Physics

Add physics simulation to your 2D game

TileMaps

Create tile-based levels and environments

Canvas Layers

Organize UI and parallax backgrounds