A lightweight HTML5 Canvas 2D framework built to make game and graphics development approachable — no dependencies, no build step, pure JavaScript.
Live demo: https://samuelsantosdev.github.io/SimpleCanvas/
HTMLElement.prototype.SimpleCanvas is attached directly to the native DOM element, allowing a clean and idiomatic API:
document.getElementById('myCanvas').SimpleCanvas().Initialize({}, callback);This keeps the entry point minimal and ties the framework lifecycle directly to the canvas element.
The Engine object is a global singleton that holds all runtime state — loaded maps, entities, controllers, libraries, and the render queue. This guarantees a single source of truth for the game loop and prevents conflicts between subsystems.
Framework modules are declared in js/config/autoload.json rather than hardcoded:
{
"Controller": ["Game"],
"Library": ["EventElementHandle"]
}At startup, simplecanvas.js reads this config and dynamically fetches only the required JS files via HTTP, keeping the initial payload small and the architecture extensible without touching core files.
Entities, maps, and controllers can be loaded on-demand during gameplay via Engine.LoadEntities(), Engine.LoadMaps(), and Engine.LoadControllers(). Each method fetches the JS file, injects it into the page, and registers the module into the Engine's registry — enabling lazy loading without a bundler.
The codebase follows a clear separation of concerns:
| Layer | Path | Responsibility |
|---|---|---|
| Core | js/core/Engine.js |
Game loop, render queue, module registry |
| Controller | js/controller/ |
Game rules and input handling |
| Entity | js/entity/ |
Game objects (e.g. SnakeBody, Stage) |
| Library | js/library/ |
Reusable tools (canvas rendering, events, maps) |
All drawable objects are registered in Engine.ObjectsRender, an ordered map. Each frame the engine iterates the queue and renders only objects with Display: true. Objects can be shown or hidden at runtime via Engine.ShowObjectRender(id) / Engine.HideObjectRender(id) without removing them from memory.
Each shape constructor (Square, Circle, Text) merges its specific properties with shared ContextShape defaults using Object.assign. This avoids deep inheritance chains and keeps shape creation flat and readable.
The framework includes a built-in animation API supporting:
- Smooth color transitions (RGBA interpolation via
Engine.Helper.ToRgba) - Positional animations to multiple coordinates with configurable duration
- Animations triggered at render time, decoupled from game logic
EventElementHandle abstracts keyboard and pointer input away from game controllers, so controllers only declare what events they care about rather than managing raw DOM listeners.
The repository uses a GitHub Actions workflow (.github/workflows/static.yml) to automatically deploy to GitHub Pages on every push to master — zero-config CI/CD for a static project.
- Clone the repository
- Open
index.htmlin a browser (or serve it with any static file server) - No build step or package installation required
| Version | Changes |
|---|---|
| 0.3 | Modernized UI, fixed CDN issues |
| 0.2 | New singleton Engine, color transition effects, multi-coordinate animations |
| 0.1 | Initial release — shape rendering, game loop, Snake example |
MIT © Samuel Santos
