2D Game Creation
G3Engine includes a powerful 2D editor for creating sprite-based games. This guide covers the 2D workflow, sprite management, layers, and 2D-specific features.Understanding the 2D Editor
The 2D editor uses a canvas-based coordinate system with:- Origin (0, 0) at the center of the canvas
- X-axis increases to the right
- Y-axis increases upward
- Default canvas size: 800×600 pixels
Working with Sprites
{
"id": "sprite-uuid",
"type": "shape",
"layerId": "layer-default",
"x": 0,
"y": 0,
"width": 50,
"height": 50,
"rotation": 0,
"scaleX": 1,
"scaleY": 1,
"opacity": 1,
"visible": true,
"shapeType": "rectangle",
"fillColor": "#6366f1",
"strokeColor": "#000000",
"strokeWidth": 0,
"cornerRadius": 0
}
{
"type": "shape",
"shapeType": "rectangle",
"width": 50,
"height": 50,
"fillColor": "#6366f1",
"cornerRadius": 0
}
{
"type": "text",
"text": "Hello World",
"fontSize": 24,
"fontFamily": "Inter, sans-serif",
"fillColor": "#f0f0f5"
}
Layer Management
Layers control rendering order and organization.{
"id": "layer-uuid",
"name": "Layer 1",
"order": 0,
"visible": true,
"locked": false,
"opacity": 1.0
}
Layer 0: Background
Layer 1: Environment
Layer 2: Enemies
Layer 3: Player
Layer 4: Effects
Layer 5: UI
2D Camera Controls
Drawing Tools
- Shape type (rectangle/circle)
- Fill color
- Stroke color and width
- Corner radius (rectangles only)
Building a 2D Platformer
{
"layerId": "platforms",
"type": "shape",
"shapeType": "rectangle",
"x": 0,
"y": -250,
"width": 800,
"height": 40,
"fillColor": "#4a4a5e",
"cornerRadius": 0
}
{
"layerId": "player",
"type": "shape",
"emoji": "🎮",
"x": -200,
"y": -180,
"width": 48,
"height": 48
}
[
{
"x": -100,
"y": -100,
"width": 120,
"height": 20,
"fillColor": "#6366f1"
},
{
"x": 100,
"y": -50,
"width": 120,
"height": 20,
"fillColor": "#6366f1"
},
{
"x": 300,
"y": 0,
"width": 120,
"height": 20,
"fillColor": "#6366f1"
}
]
2D Physics & Interactivity
While the 2D editor provides the visual layout, interactivity is added through visual scripting:- Switch to the Node Editor (Bottom Panel)
-
Add event nodes for 2D-specific events:
- On Key Press - Player input
- On Collision 2D - Sprite collisions
- On Click - Mouse/touch interactions
-
Add action nodes for 2D manipulation:
- Move To - Animate sprite position
- Set Sprite Property - Change color, opacity, size
- Play Animation - Sprite animation sequences
- Add “On Key Press” event node
- Add “Move To” action node
- Connect execution flow
- Set target to player sprite
- Calculate new position based on key
Grid and Guides
Export and Runtime
{
"version": 1,
"type": "2d",
"canvas": {
"width": 800,
"height": 600,
"backgroundColor": "#1a1a2e"
},
"layers": [
{
"id": "layer-1",
"name": "Background",
"order": 0,
"visible": true,
"locked": false,
"opacity": 1.0
}
],
"sprites": [
{
"id": "sprite-1",
"layerId": "layer-1",
"type": "shape",
"x": 0,
"y": 0,
"width": 50,
"height": 50,
"fillColor": "#6366f1"
}
]
}
Tips for 2D Games
Use Layers Wisely
Separate background, gameplay, and UI into distinct layers for easier editing and performance.
Grid Alignment
Enable snap-to-grid for pixel-perfect positioning, especially important for platformers.
Emoji as Sprites
Emojis make great placeholder art. Use the emoji property for quick prototyping.
Center Your Scene
Work around the origin (0,0) for easier camera and physics management.
Common 2D Game Patterns
Side-Scrolling Platformer
Side-Scrolling Platformer
- Canvas: 800×600
- Player on left side of screen (x: -200)
- Platforms extending to the right
- Camera follows player X position
- Grid: 16px for tile alignment
Top-Down Adventure
Top-Down Adventure
- Canvas: 800×800 (square)
- Player at center (0, 0)
- Environment arranged around player
- Camera follows player position (X and Y)
- Grid: 32px for room/tile design
Puzzle Game
Puzzle Game
- Canvas: 600×800 (portrait)
- Fixed camera (no following)
- Grid-aligned pieces (64px grid)
- UI layer for score/timer
- High layer count for piece depth sorting
Shooter Game
Shooter Game
- Canvas: 800×600
- Player at bottom center (y: -200)
- Enemies spawn at top
- Bullets on separate layer
- No grid needed (free movement)
Next Steps
- Adding Interactivity - Visual scripting for 2D games
- Publishing Games - Deploy your 2D game
- 3D Scene Setup - Compare with 3D workflow