@tknight-dev/gaming-canvas
v1.18.4
Published
A better/faster way to start writing games
Downloads
191
Maintainers
Readme
Gaming Canvas · 

Supports
CommonJS(.cjs) andESM(.mjs)- Multithreading (WebWorkers)
- Designed take full advantage of multiple threads in JavaScript
- Check out the documentation Tips & Tricks: Multithreading to learn more
Why This Library?
GamingCanvas is for the game developer that wants to write their own game or engine, their own way, rather than usings solutions like PixiJs and Phaser. It provides the following to get you up and running:
- Audio: The built in audio system provides buffers which allow you to play multiple audio files at the same time (even the same audio file)
- Update the pan and volume of the effect or music depending on your game's environment!
- Use faders to automatically evolve your pan and volume values to your desired settings over a duration of milliseconds
- Use fader callback chaining to perfectly time more complicated pan and volume changes over a series of actions
- DPI: Supports high/low DPI screens (devicePixelRatio)
- Fullscreen: Quickly fullscreen your game
- Inputs: Gives you access to Gamepad, Keyboard, Mouse, and Touch via a serialized (FIFO) input queues
- Enable or disable any input type you want
- Gamepad: Support currently excludes triggers due to different browser bugs/implementations of the Gamepad API
- Mouse: Supports left, right, and wheel based inputs
- Touch: Supports as many individual inputs as your screen can support
- Layers: Specify how many layers you want to optimize your game for. It can generate multiple canvases for background, foreground, overlay-1, etc, etc
- Send each layer to a different WebWorker to dedicate a thread to each canvas element (massive performance gains) (multithreading)
- Lists: Provides
Listimplementions whereArrayperformance faulters- Double-Linked-List
- FIFO Queue (Single-Linked-List without
popEnd()orpushStart())
- Lightweight: Core library is ~45kb
- Modules
- Grids: Includes Grid, Camera, Path Finding (A*), Raycasting, and Viewport implementations. See How-To > Module: Grids for all the features and details
- Mobile: Mobile devices are fully supported
- Orientation: Auto rotate for maximum screen usage or lock it to a specific orientation (Portrait/Landscape)
- Screen Orientation locking isn't supported by all browsers
- Resolution: Use a fixed resolution to optimize your FPS (it still scales to fill the screen like a regular video game would)
- Dimensions are always rounded down to the nearest pixel to improve performance
- Scaling uses the css
transform: scale(x)function which your browser (CPU) offloads to your GPU (best performance) - Use the
aspectRatiooption to lock your display to something like1 / 1,4 / 3, and16 / 9(the default)
- Splitscreen: A no hassle way to split your screen for 2 players (2 canvases sharing the space of 1 canvas)
- Vibration: Set vibration (think mobile device vibration during an incoming phone call) for single use or repeating patterns
- Not supported by all browsers (MDN)
- Visibility: Quickly know if your game needs to be paused (browser minimized or switched to new tab)
- Wake Lock: Quickly prevent mobile devices from dimming the screen while you're playing
See the GamingCanvas in action in the following games:
- Life, A multithreaded Conway's Game of Life for Desktop and Mobile devices (supports Gamepad, Keyboard, Mouse, and Touch based inputs) [GitHub]
- Wolfenstein3D, A multithreaded (+Multiplayer) rewrite of Id Software's 1992 release (supports Gamepad, Keyboard, Mouse, and Touch based inputs) [GitHub]
Documentation
Link: Documentation
