Generated banner for Game Engine
Generated logo for Game Engine

Game Engine

GitHubOfficialFirst committed by jhaugaDistributed by GitHub

  • Skill
  • Tool integration
  • Software development
  • MIT
  • No issues found

From the author

Expert skill for building web-based game engines and games using HTML5, Canvas, WebGL, and JavaScript. Use when asked to create games, build game engines, implement game physics, handle collision detection, set up game loops, manage sprites, add game controls, or work with 2D/3D rendering. Covers techniques for platformers, breakout-style games, maze games, tilemaps, audio, multiplayer via WebRTC, and publishing games.
— the description by jhauga

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The Game Engine skill provides a structured approach to developing interactive 2D and 3D games for the web. It covers the entire lifecycle of game development, from core engine architecture—such as the game loop and rendering pipelines—to specific implementations of physics, collision detection, and input handling. The skill includes reference documentation on web APIs, algorithms, and 3D theory, alongside practical templates for common game types like platformers and maze games.

What it does

  • Provides workflows for building game engines and games from scratch.
  • Explains core concepts like game loops, rendering, and physics.
  • Offers reference material for WebGL, Canvas, and Web Audio APIs.
  • Includes starter templates for 2D platformers and breakout-style games.
  • Covers advanced topics like raycasting, collision detection, and multiplayer networking.
  • Guides users through asset optimization and game publishing.

When to use it

  • When you need to build a web-based game or a custom game engine.
  • When implementing game mechanics like physics, collision, or input controls.
  • When you need to understand 3D rendering pipelines or WebGL fundamentals.
  • When you are looking for starter code for 2D or 3D web game projects.
  • When you need to optimize game performance or handle cross-browser audio issues.

Advantages

  • Centralizes essential game development knowledge for the web.
  • Provides ready-to-use templates to accelerate project setup.
  • Offers clear, step-by-step procedures for common game development tasks.
  • Includes troubleshooting guides for common rendering and performance issues.
  • Supports both 2D (Canvas) and 3D (WebGL/Three.js) development workflows.

Usage examples

“How do I set up a basic game loop using requestAnimationFrame?”
The agent provides a code structure that initializes a canvas, defines an update function for game logic, and a render function for drawing, tied together by a recursive requestAnimationFrame call.
“Can you help me implement AABB collision detection for my 2D platformer?”
The agent explains the Axis-Aligned Bounding Box algorithm and provides a JavaScript function to check if two rectangular objects overlap.
“What are the steps to publish my web game?”
The agent outlines a checklist including asset compression, code minification, cross-browser testing, and choosing a distribution platform.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/github/game-engine/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip game-engine.zip -d .agents/skills

Documentation by jhauga

Game Engine Skill

Build web-based games and game engines using HTML5 Canvas, WebGL, and JavaScript. This skill includes starter templates, reference documentation, and step-by-step workflows for 2D and 3D game development with frameworks such as Phaser, Three.js, Babylon.js, and A-Frame.

When to Use This Skill

  • Building a game engine or game from scratch using web technologies

  • Implementing game loops, physics, collision detection, or rendering

  • Working with HTML5 Canvas, WebGL, or SVG for game graphics

  • Adding game controls (keyboard, mouse, touch, gamepad)

  • Creating 2D platformers, breakout-style games, maze games, or 3D experiences

  • Working with tilemaps, sprites, or animations

  • Adding audio to web games

  • Implementing multiplayer features with WebRTC or WebSockets

  • Optimizing game performance

  • Publishing and distributing web games

Prerequisites

  • Basic knowledge of HTML, CSS, and JavaScript

  • A modern web browser with Canvas/WebGL support

  • A text editor or IDE

  • Optional: Node.js for build tooling and local development servers

Core Concepts

The following concepts form the foundation of every web-based game engine.

Game Loop

Every game engine revolves around the game loop -- a continuous cycle of:

  1. Process Input - Read keyboard, mouse, touch, or gamepad input

  2. Update State - Update game object positions, physics, AI, and logic

  3. Render - Draw the current game state to the screen

Use requestAnimationFrame for smooth, browser-optimized rendering.

Rendering
  • Canvas 2D - Best for 2D games, sprite-based rendering, and tilemaps

  • WebGL - Hardware-accelerated 3D and advanced 2D rendering

  • SVG - Vector-based graphics, good for UI elements

  • CSS - Useful for DOM-based game elements and transitions

Physics and Collision Detection
  • 2D Collision Detection - AABB, circle, and SAT-based collision

  • 3D Collision Detection - Bounding box, bounding sphere, and raycasting

  • Velocity and Acceleration - Basic Newtonian physics for movement

  • Gravity - Constant downward acceleration for platformers

Controls
  • Keyboard - Arrow keys, WASD, and custom key bindings

  • Mouse - Click, move, and pointer lock for FPS-style controls

  • Touch - Mobile touch events and virtual joysticks

  • Gamepad - Gamepad API for controller support

Audio
  • Web Audio API - Programmatic sound generation and spatial audio

  • HTML5 Audio - Simple audio playback for music and sound effects

Step-by-Step Workflows

Creating a Basic 2D Game
  1. Set up an HTML file with a <canvas> element

  2. Get the 2D rendering context

  3. Implement the game loop using requestAnimationFrame

  4. Create game objects with position, velocity, and size properties

  5. Handle keyboard/mouse input for player control

  6. Implement collision detection between game objects

  7. Add scoring, lives, and win/lose conditions

  8. Add sound effects and music

Building a 3D Game
  1. Choose a framework (Three.js, Babylon.js, A-Frame, or PlayCanvas)

  2. Set up the scene, camera, and renderer

  3. Load or create 3D models and textures

  4. Implement lighting and shaders

  5. Add physics and collision detection

  6. Implement player controls and camera movement

  7. Add audio and visual effects

Publishing a Game
  1. Optimize assets (compress images, minify code)

  2. Test across browsers and devices

  3. Choose distribution platform (web, app stores, game portals)

  4. Implement monetization if needed

  5. Promote through game communities and social media

Game Templates

Starter templates are available in the assets/ folder. Each template provides a complete, working example that can be used as a starting point for a new project.

TemplateDescription
paddle-game-template.md2D Breakout-style game with pure JavaScript
2d-maze-game.mdMaze game with device orientation controls
2d-platform-game.mdPlatformer game using Phaser framework
gameBase-template-repo.mdGame base template repository structure
simple-2d-engine.mdSimple 2D platformer engine with collisions

Reference Documentation

Detailed reference material is available in the references/ folder. Consult these files for in-depth coverage of specific topics.

ReferenceTopics Covered
basics.mdGame development introduction and anatomy
web-apis.mdCanvas, WebGL, Web Audio, Gamepad, and other web APIs
techniques.mdCollision detection, tilemaps, async scripts, audio
3d-web-games.md3D theory, frameworks, shaders, WebXR
game-control-mechanisms.mdTouch, keyboard, mouse, and gamepad controls
game-publishing.mdDistribution, promotion, and monetization
algorithms.mdRaycasting, collision, physics, vector math
terminology.mdGame development glossary
game-engine-core-principles.mdCore design principles for game engines

Troubleshooting

IssueSolution
Canvas is blankCheck that you are calling drawing methods after getting the context and inside the game loop
Game runs at different speedsUse delta time in update calculations instead of fixed values
Collision detection is inconsistentUse continuous collision detection or reduce time steps for fast-moving objects
Audio does not playBrowsers require user interaction before playing audio; trigger playback from a click handler
Performance is poorProfile with browser dev tools, reduce draw calls, use object pooling, and optimize asset sizes
Touch controls are unresponsivePrevent default touch behavior and handle touch events separately from mouse events
WebGL context lostHandle the webglcontextlost event and restore state on webglcontextrestored

Files

references/basics.md

Game Development Basics

A comprehensive reference covering web game development technologies, game architecture, and the anatomy of a game loop.

Sources:


Web Technologies for Game Development

Graphics and Rendering
  • WebGL -- Hardware-accelerated 2D and 3D graphics based on OpenGL ES 2.0. Provides direct GPU access for high-performance rendering.

  • Canvas API -- 2D drawing surface via the <canvas> element. Suitable for 2D games, sprite rendering, and pixel manipulation.

  • SVG -- Scalable Vector Graphics for resolution-independent visuals. Useful for UI elements and simple vector-based games.

  • HTML/CSS -- Standard web technologies for building game UI, menus, HUDs, and overlays.

Audio
  • Web Audio API -- Advanced audio engine supporting real-time playback, synthesis, spatial audio, effects processing, and dynamic mixing.

  • HTML Audio Element -- Simple sound playback for background music and basic sound effects.

Input and Controls
  • Gamepad API -- Support for game controllers and gamepads, including button mapping and analog stick input.

  • Touch Events API -- Multi-touch input handling for mobile devices.

  • Pointer Lock API -- Locks the mouse cursor within the game area and provides raw coordinate deltas for precise camera/aiming control.

  • Device Sensors -- Accelerometer and gyroscope access for motion-based input.

  • Full Screen API -- Enables immersive full-screen game experiences.

Networking and Multiplayer
  • WebSockets API -- Persistent, bidirectional communication channel for real-time multiplayer, chat, and live updates.

  • WebRTC API -- Peer-to-peer connections for low-latency multiplayer, voice chat, and data channels.

  • Fetch API -- HTTP requests for downloading game assets, loading level data, and transmitting non-real-time game state.

Data Storage and Performance
  • IndexedDB API -- Client-side structured storage for save games, cached assets, and offline play support.

  • Typed Arrays -- Direct access to raw binary data buffers for GL textures, audio samples, and compact game data.

  • Web Workers API -- Background thread execution for offloading heavy computations (physics, pathfinding, AI) without blocking the main thread.

Languages and Compilation
  • JavaScript -- The primary language for web game development.

  • C/C++ via Emscripten -- Compile existing native game code to JavaScript or WebAssembly for web deployment.

  • WebAssembly (Wasm) -- Near-native execution speed for performance-critical game code.


Types of Games You Can Build

The modern web platform supports a full range of game types:

  • 3D action games and shooters

  • Role-playing games (RPGs)

  • 2D platformers and side-scrollers

  • Puzzle and strategy games

  • Card and board games

  • Casual and mobile-friendly games

  • Multiplayer experiences with real-time networking


Advantages of Web-Based Game Development

  1. Universal reach -- Games run on smartphones, tablets, PCs, and Smart TVs through the browser.

  2. No app store dependency -- Deploy directly on the web without store approval processes.

  3. Full revenue control -- No mandatory revenue share; use any payment processing system.

  4. Instant updates -- Push updates immediately without waiting for store review.

  5. Own your analytics -- Collect your own data or choose any analytics provider.

  6. Direct player relationships -- Engage players without intermediaries.

  7. Inherent shareability -- Games are linkable and discoverable via standard web mechanisms.


Anatomy of a Game Loop

Every game operates through a continuous cycle of steps:

  1. Present -- Display the current game state to the player.

  2. Accept -- Receive user input (keyboard, mouse, gamepad, touch).

  3. Interpret -- Process raw input into meaningful game actions.

  4. Calculate -- Update the game state based on actions, physics, AI, and time.

  5. Repeat -- Loop back to present the updated state.

Games may be event-driven (turn-based, waiting for player action) or per-frame (continuously updating via a main loop).


Building a Game Loop with requestAnimationFrame

Basic Main Loop
window.main = () => {
  window.requestAnimationFrame(main);

  // Your game logic here: update state, render frame
};

main(); // Start the cycle

Key points:

  • requestAnimationFrame() synchronizes callbacks to the browser's repaint schedule (typically 60 Hz).

  • Schedule the next frame before performing loop work to maximize available computation time.

Self-Contained Main Loop (IIFE)
;(() => {
  function main() {
    window.requestAnimationFrame(main);

    // Game logic here
  }

  main();
})();
Stoppable Main Loop
;(() => {
  function main() {
    MyGame.stopMain = window.requestAnimationFrame(main);

    // Game logic here
  }

  main();
})();

// To stop the loop:
window.cancelAnimationFrame(MyGame.stopMain);

Timing and Frame Rate

DOMHighResTimeStamp

requestAnimationFrame passes a DOMHighResTimeStamp to your callback, providing timing precision to 1/1000th of a millisecond.

;(() => {
  function main(tFrame) {
    MyGame.stopMain = window.requestAnimationFrame(main);

    // tFrame is a high-resolution timestamp in milliseconds
    // Use it for delta-time calculations
  }

  main();
})();
Frame Time Budget

At 60 Hz, each frame has approximately 16.67ms of available processing time. The browser's frame cycle is:

  1. Start new frame (previous frame displayed to screen)

  2. Execute requestAnimationFrame callbacks

  3. Perform garbage collection and per-frame browser tasks

  4. Sleep until VSync, then repeat


Simple Update and Render Pattern

The simplest approach when your game can sustain the target frame rate:

;(() => {
  function main(tFrame) {
    MyGame.stopMain = window.requestAnimationFrame(main);

    update(tFrame); // Process game logic
    render();       // Draw the frame
  }

  main();
})();

Assumptions:

  • Each frame can process input and update state within the time budget.

  • The simulation runs at the same rate as the display refresh (typically ~60 FPS).

  • No frame interpolation is needed.


Decoupled Update and Render with Fixed Timestep

For robust handling of variable refresh rates and consistent simulation behavior:

;(() => {
  function main(tFrame) {
    MyGame.stopMain = window.requestAnimationFrame(main);
    const nextTick = MyGame.lastTick + MyGame.tickLength;
    let numTicks = 0;

    // Calculate how many simulation updates are needed
    if (tFrame > nextTick) {
      const timeSinceTick = tFrame - MyGame.lastTick;
      numTicks = Math.floor(timeSinceTick / MyGame.tickLength);
    }

    queueUpdates(numTicks);
    render(tFrame);
    MyGame.lastRender = tFrame;
  }

  function queueUpdates(numTicks) {
    for (let i = 0; i < numTicks; i++) {
      MyGame.lastTick += MyGame.tickLength;
      update(MyGame.lastTick);
    }
  }

  MyGame.lastTick = performance.now();
  MyGame.lastRender = MyGame.lastTick;
  MyGame.tickLength = 50; // 20 Hz simulation rate (50ms per tick)

  setInitialState();
  main(performance.now());
})();

Benefits:

  • Deterministic simulation -- Game logic runs at a fixed frequency regardless of display refresh rate.

  • Smooth rendering -- Rendering can interpolate between simulation states for visual smoothness.

  • Portable behavior -- Game behaves the same on 60 Hz, 120 Hz, and 144 Hz displays.


Alternative Architecture Patterns

Separate setInterval for Updates
// Game logic updates at a fixed rate
setInterval(() => {
  update();
}, 50); // 20 Hz

// Rendering synchronized to display
requestAnimationFrame(function render(tFrame) {
  requestAnimationFrame(render);
  draw();
});

Drawback: setInterval continues running even when the tab is not visible, wasting resources.

Web Worker for Updates
// Heavy game logic runs in a background thread
const updateWorker = new Worker('game-update-worker.js');

requestAnimationFrame(function render(tFrame) {
  requestAnimationFrame(render);
  updateWorker.postMessage({ ticks: numTicksNeeded });
  draw();
});

Benefits: Does not block the main thread. Ideal for physics-heavy or AI-intensive games. Drawback: Communication overhead between worker and main thread.

requestAnimationFrame Driving a Web Worker
;(() => {
  function main(tFrame) {
    MyGame.stopMain = window.requestAnimationFrame(main);

    // Signal worker to compute updates
    updateWorker.postMessage({
      lastTick: MyGame.lastTick,
      numTicks: calculatedNumTicks
    });

    render(tFrame);
  }

  main();
})();

Benefits: No reliance on legacy timers. Worker performs computation in parallel.


Handling Tab Focus Loss

When a browser tab loses focus, requestAnimationFrame slows down or stops entirely. Strategies:

StrategyDescriptionBest For
Treat gap as pauseSkip elapsed time; do not updateSingle-player games
Simulate the gapRun all missed updates on regainSimple simulations
Sync from server/peerFetch authoritative stateMultiplayer games

Monitor the numTicks value after a focus-regain event. A very large value indicates the game was suspended and may need special handling rather than trying to simulate all missed frames.


Comparison of Timing Approaches

ApproachProsCons
Simple update/render per frameEasy to implement, responsiveBreaks on slow/fast hardware
Fixed timestep + interpolationConsistent simulation, smooth visualsMore complex to implement
Quality scalingMaintains frame rate dynamicallyRequires adaptive quality systems

Performance Best Practices

  • Detach non-frame-critical code from the main loop. Use events and callbacks for UI, network responses, and other asynchronous operations.

  • Use Web Workers for computationally expensive tasks like physics, pathfinding, and AI.

  • Leverage GPU acceleration through WebGL for rendering.

  • Stay within the frame budget -- monitor your update + render time to keep it under 16.67ms for 60 FPS.

  • Throttle garbage collection pressure by reusing objects and avoiding per-frame allocations.

  • Plan your timing strategy early -- changing the game loop architecture mid-development is difficult and error-prone.


  • Three.js -- General-purpose 3D library with a large ecosystem.

  • Babylon.js -- Full-featured 3D game engine with physics, audio, and scene management.

  • A-Frame -- Declarative 3D/VR framework built on Three.js.

  • PlayCanvas -- Cloud-hosted 3D game engine with a visual editor.

  • Phaser -- Popular 2D game framework with physics and input handling.

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

First committed by
GitHub avatar of jhaugajhauga
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/game-engine · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
jhauga

AutoGineer is not affiliated with or endorsed by jhauga or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download game-engine.zip