Introduction
Godot provides a comprehensive 2D engine for creating games and applications. All 2D nodes inherit fromNode2D, 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
TheNode2D class is the foundation for all 2D objects. It provides transformation properties and methods for positioning and orienting nodes in 2D space.
Transform Properties
| Property | Type | Description |
|---|---|---|
position | Vector2 | Position relative to parent node |
rotation | float | Rotation in radians |
rotation_degrees | float | Rotation in degrees (helper property) |
scale | Vector2 | Scale relative to parent |
skew | float | Skew transformation in radians |
Global Transform Properties
Every transform property has a global equivalent:global_positionglobal_rotation/global_rotation_degreesglobal_scaleglobal_skewglobal_transform
Basic Movement
Transform Methods
Coordinate Conversion
Convert between local and global coordinates:Z-Index and Draw Order
Thez_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
TheCamera2D node controls what portion of the 2D scene is visible.
Basic Camera Setup
Camera Following
Attach aCamera2D 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: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 theshadow_enabled property. Configure shadow properties:
Transform Hierarchy
Transforms are hierarchical. A child node’s transform is relative to its parent:Best Practices
Use local transforms for relative movement
Use local transforms for relative movement
When moving nodes relative to their parent, use local transform properties like
position and rotate().Use global transforms for absolute positioning
Use global transforms for absolute positioning
For world-space positioning (like spawning projectiles), use
global_position.Camera on player vs separate
Camera on player vs separate
Attach the camera to the player for simple following. Use a separate camera node with scripting for more complex behavior.
Negative Y for upward movement
Negative Y for upward movement
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