← Textbook
Interactive Textbook · Chapter 02

Game Engines, Libraries, and 3D Reloads

The same idea can become totally different games depending on the library. Learn how to pick the right tool — and rebuild a 2D prototype as a 3D Three.js game.

For parents:Students learn that AI doesn't build from nothing — it stitches together libraries written by humans. Picking the right library is a real software engineering decision, and this chapter teaches that judgment using small, concrete game ideas.
Section 2.1

The secret: Lovable does not build from nothing

When you type a prompt into Lovable, it isn't inventing every piece of technology from scratch. It is usually building with existing web libraries and packages. That matters because different libraries are good at different things.

A beginner says "build me a game." A stronger builder says "build this as a 2D browser game using Phaser." An even stronger builder says "rebuild this game in Three.js so it becomes a 3D version while keeping the same core gameplay."

Section 2.2

What is a library?

A library is reusable code that helps developers build faster. If you were building a house, you wouldn't forge your own hammer from raw metal. Real builders use tools.

  • A physics library helps with gravity and collisions.
  • A 3D library helps draw 3D worlds.
  • A state library helps remember game data.
  • A UI library helps create buttons, cards, menus.
  • A database tool helps save scores, profiles, projects.
Section 2.3

Why libraries matter for games

Games are more complicated than normal websites. They need movement, collision, gravity, animation, enemies, levels, cameras, particles, sound, score, health, physics, 3D, and sometimes multiplayer state.

If you ask Lovable to build all of that from scratch it might work, but it'll get messy. A library gives the AI a stronger foundation — like saying "use a bike frame" instead of "invent a vehicle from random parts."

Section 2.4

Common libraries and what they're good for

React
Good for:Pages, dashboards, portfolios, prompt generators.
Use when:I want a clean app or studio website.
Build this as a React app with clean reusable components.
Tailwind CSS
Good for:Layout, colors, spacing, responsive design.
Use when:I want polished, game-like styling.
Use Tailwind CSS to make the menu colorful and responsive.
shadcn/ui
Good for:Buttons, cards, dialogs, tabs, forms, dashboards.
Use when:I want a polished app interface fast.
Use shadcn/ui for the dashboard, cards, dialogs, and forms.
Canvas
Good for:Simple 2D games, drawing, arcade & catching games.
Use when:I want a lightweight game with custom drawing.
Build this as an HTML Canvas game with keyboard controls, score, and restart.
Phaser
Good for:Platformers, arcade games, sprites, tile maps, physics.
Use when:I want a serious 2D game engine.
Rebuild this game using Phaser so movement, collisions, and sprite animations are reliable.
PixiJS
Good for:Fast, smooth 2D graphics and particle effects.
Use when:I want the game to look smoother and more animated.
Use PixiJS for a smooth 2D arcade with animated sprites and particles.
Matter.js
Good for:Gravity, bouncing, collisions, physics puzzles.
Use when:I want realistic physics.
Use Matter.js to add gravity, bouncing, and collisions.
Three.js
Good for:3D worlds, cameras, lighting, 3D objects.
Use when:I want my game to look 3D.
Rebuild this game using three.js so the world, player, obstacles, and camera feel 3D.
React Three Fiber
Good for:3D scenes built with React components.
Use when:I want a 3D game inside a React app with reusable components.
Use React Three Fiber to build the 3D scene with reusable React components.
Zustand
Good for:Score, health, level, inventory, current screen.
Use when:I need the app to remember game info across components.
Use Zustand to manage score, lives, current level, game mode, and upgrades.
Supabase
Good for:Saved data, portfolios, leaderboards, shared catalogs.
Use when:I need my game or portal to save info.
Connect this game portal to Supabase to save submissions with studio nickname + score.
Section 2.5

The library choice changes the game

The same idea — "a player runs away from an evil sphere" — becomes different games depending on the library:

Canvas
Simple shapes, top-down movement, fast prototype.
Phaser
Smoother 2D, sprites, levels, arcade feel.
Three.js
3D sphere, camera perspective, lighting, depth.
React app
Dashboard, menu, settings, portfolio page.
Supabase
Saved scores, leaderboard, class gallery.
Matter.js
Physics-driven sphere, rolling, ramps, bounces.
Section 2.6

When should you use Three.js?

Use Three.js when the game idea actually needs 3D. Good fits:

  • Escape a 3D maze
  • Dodge spheres in an arena
  • Fly through rings
  • Explore a planet
  • Roll a ball through obstacles
  • Survive waves of enemies
  • Walk around a 3D gallery

A quiz game, word puzzle, or simple catching game usually doesn't need 3D. Three.js is powerful but adds complexity. Use it when 3D makes the game more fun, not just to show off.

Section 2.7

Prompt: Rebuild my game in 3D

This prompt is the one that took a 2D game called Fear the Sphereand produced Fear the Sphere Reloaded — a 3D Three.js version on a separate route.

Fear the Sphere
V1.0 · 2D
Fear the Sphere
Original 2D survival arena.
FtSR
V0.1 · 3D
Fear the Sphere Reloaded
Faithful 3D rebuild in Three.js. Lives at /reloaded.
Yg·R
Your turn
Your game · Reloaded
Pick a game you've built and 3D-reload it.
Build Lab

Three.js Reload Prompt

Fill in your current game. We'll generate a 'faithful rebuild' prompt that puts the 3D version on its own route and preserves the original.

Your generated prompt
I want you to try and build a completely separate game called "[CURRENT GAME TITLE] Reloaded" and make it a faithful rebuild of "[CURRENT GAME TITLE]", but using three.js so that everything looks like it is in 3D.

Keep the same core idea, mood, controls, and game loop from the current version, but rebuild the visuals and play space as a 3D game.

Focus on the main mode first.

Put the new version in /reloaded.

Keep going until the /reloaded version is playable.

Requirements:
- Use three.js for the 3D scene.
- Create a 3D arena or play space.
- Represent the player and key objects as 3D meshes.
- Add lighting, camera perspective, and depth.
- Keep the controls simple and responsive.
- Include a title or start screen.
- Include clear instructions.
- Include score, wave/level number, and health or lives if relevant.
- Include restart.
- Make the first wave easy enough to learn.
- Keep the original version working — do NOT replace it.
- Build this as a separate route at /reloaded.
Section 2.8

Faithful rebuild vs. remix

Faithful rebuild

Same core idea, new technology. Fear the Sphere Reloaded is still about surviving waves and avoiding the sphere — it just looks 3D now.

Remix

Same starting point, new idea. Turn Fear the Sphere into a space survival game where the sphere becomes a black hole and the player pilots a tiny ship.

Both are useful. A rebuild asks "how can this game become stronger with new tech?" A remix asks "how can this idea transform into something new?"

Section 2.9

Prompt: Choose the best library for my game

If you're not sure which library to use, ask Lovable to help you choose. That's what real developers do.

Build Lab

Library Recommender Prompt

Your generated prompt
Analyze my current game idea and recommend the best technical approach.

My game idea:
[DESCRIBE GAME]

Compare these options:
- simple React app
- HTML Canvas
- Phaser
- PixiJS
- Matter.js
- Three.js
- React Three Fiber

For each option, explain:
1. What it would be good at
2. What might be difficult
3. Whether it fits my game
4. How hard it would be to build

Then recommend the best option for a V0.1 first build. Keep the explanation student-friendly.
Section 2.10

Prompt: Convert my game to Phaser

Build Lab

Phaser Conversion Prompt

Use this when a simple game needs stronger 2D mechanics.

Your generated prompt
Rebuild "[GAME]" as a Phaser-based 2D browser game.

Keep the same title, core goal, player character, theme, and basic game loop.

Use Phaser for:
- player movement
- collision detection
- collectibles
- hazards
- level layout
- score
- win/lose states

Put the Phaser version in /phaser-version. Do not remove the current version.

Make the first version small and playable: title screen, clear controls, safe starting zone, restart button, simple win condition, one short level.

After building it, explain what changed and why Phaser is useful for this kind of game.
Section 2.11

Prompt: Add physics with Matter.js

Build Lab

Matter.js Physics Prompt

Use this when a game needs gravity, bouncing, ramps, or physics puzzles.

Your generated prompt
Add a new physics-based version of "[GAME]" using Matter.js.

Put it in /physics. Keep the same theme and main character, but use physics as the main mechanic.

Add: gravity, collision, bouncing or rolling objects, obstacles, a clear goal, restart button, simple instructions.

Make it playful and easy to test. Do not remove the current game.

After building it, explain which parts use Matter.js and how the physics changes the gameplay.
Section 2.12

Prompt: Add saved scores with Supabase

Build Lab

Supabase Leaderboard Prompt

Your generated prompt
Add a saved score system to "[GAME]" using Supabase.

Before making changes, explain what data needs to be stored.

Create a simple leaderboard that saves:
- player studio nickname
- score
- game title
- date submitted

Safety:
- Do not ask for real names.
- Do not ask for emails.
- Do not store private information.
- Use studio nicknames only.

Add: submit score button, leaderboard page, and a teacher-friendly note explaining what data is stored.

Make sure the game still works if the leaderboard fails.
Section 2.13

Prompt: Turn my game into a reusable engine

This is one of the most important studio moves. You're no longer making one game — you're making the tool that helps you make the next one.

Build Lab

Reusable Starter Kit Prompt

Your generated prompt
Turn "[GAME]" into a reusable game starter kit.

Keep the current game working, but organize the project so I can build more games faster.

Create reusable systems for:
- title screen
- instructions
- player controls
- score
- timer
- lives or health
- levels
- collectibles
- obstacles
- win screen
- lose screen
- restart button
- game settings
- version badge

Create a new page called /builder-kit that explains how to reuse these systems.

Add copyable prompts for: make a new game using this starter, change the theme, add a level, add a power-up, make it easier, make it harder, fix a bug using Reality vs. Expected, polish for publishing.

Keep the explanation student-friendly. Do not overcomplicate the code.
Section 2.14

Prompt: Build a library comparison page inside my project

Library Comparison Page
Add a new page called /game-libraries that teaches students about the different libraries and tools this project could use to build games.

Include sections for: React, Tailwind, shadcn/ui, Canvas, Phaser, PixiJS, Matter.js, Three.js, React Three Fiber, Zustand, Supabase.

For each one, explain:
1. What it is
2. What it is good for
3. When a student should use it
4. One example prompt

Keep the writing friendly for ages 14–16.

Add a "Choose My Engine" wizard where students answer:
- Is your game 2D or 3D?
- Does it need physics?
- Does it need saved scores?
- Does it need multiplayer or shared data?
- Does it need a polished website or dashboard?
- Is it mostly a simple prototype?

Then recommend one or two tools and generate a starter prompt.
Section 2.15

How to think like a technical director

A studio's technical director asks: What are we building? What tools should we use? What should stay simple? What might break? What should be reusable? What should we build first? What should we avoid for V0.1?

Section 2.16

The 'upgrade path' mindset

V0.1
Canvas
Basic idea exists.
V0.2
Phaser
Movement & collisions improve.
V0.3
Three.js
Game becomes 3D.
V0.4
Supabase
Scores get saved.
V1.0
Studio
Landing page, polish, portfolio card.

You don't build everything at once. Build one version, then unlock the next level.

Section 2.17

Chapter challenge: Reload your game

Take one game you've built and create a new version using a different library.

  1. Pick a current game and note its version (V0.1 / V0.2 / V1.0).
  2. Choose an upgrade: 3D, better 2D, physics, leaderboard, reusable kit, studio site.
  3. Pick the library to use.
  4. Use one of the prompt forms in this chapter to generate the upgrade prompt.
  5. Do not delete the original. Put the new version on a new route like /reloaded, /phaser-version, /physics, /studio, or /builder-kit.
  6. Compare. What's better? What's harder? What would you improve next?
Section 2.18

What you should understand now

  • Lovable can use libraries and npm packages to build more advanced projects.
  • A library is reusable code that helps developers build faster.
  • Different libraries are good for different kinds of games.
  • Three.js helps create 3D browser games.
  • Phaser is useful for serious 2D games.
  • Matter.js helps with physics.
  • Supabase helps save data.
  • Choosing the right tool is part of game development.
  • You can rebuild the same game using a different technical approach.
  • Preserve old versions instead of replacing them.
  • A studio gets stronger when it turns games into reusable systems.