Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Seriously simple. Just plain ol' tiles n' units. You'll have to use other modules or build your own parts to run around this. See example.
npm install gameboard
Running the following will browserify example and open a browser window for you.
npm install && npm run example
var assets = require('./some-image-loader');
var GameBoard = require('gameboard');
var canvas = document.getElementById('gameCanvas');
var gameBoard = new GameBoard({
canvas: canvas,
tileSize: 16, // px
width: 10, // in tiles
height: 10, // in tiles
FPS: 45,
assets: assets,
grid: true // really slows down performance
});
gameBoard.start();
Returns a new instance of GameBoard. You can init with tiles already and units in place already. Must supply canvas.
canvas
- requiredtileSize
- optional (default: 16px)FPS
- optional (default: 30)assets
- optional (see Assets below)grid
- (default false)Draws the gameBoard without kicking off the render loop.
Clears the game board.
Kicks off the render()
which calls clear()
and draw()
at rate of GameBoard.FPS
. It is limited by requestAnimationFrame
.
Best way to update the gameBoard. Tiles get parsed through, units pulled out of the individual tiles, sorted and put into GameBoard.units
. Tiles are then rendered in the render()
loop. If not in the render()
loop, you can call draw() after.e
var newUnit = {
style: 'woman',
size: [1,2],
location: { x: 0, y: 0 }
};
var tiles = [
{
location: { x: 0, y: 0 },
style: 'grass_a',
visible: true,
units: [newUnit]
},
{
location: { x: 1, y: 0 },
style: 'grass_a',
visible: true,
units: []
}
];
gameBoard.tileUpdate(tiles);
Convenience method to directly draw a tile to canvas.
If render()
loop is active, tile will be added to GameBoard.tiles
.
Convenience method to directly draw a unit to canvas. If render()
loop is active, unit will be added to GameBoard.units
.
{
location: [object],
style: 'string',
visible: 'boolean',
units: 'array'
}
location
is an object with x and y.units
is an array of Unit
objects (see below)visible
boolean value. Invisible tiles won't be drawn.units
is an array of Unit
objects.{
style: 'string',
size: ['xSize', 'ySize'],
location: [object]
}
location
is an object with x and y.size
defines how many tiles it occupies. (i.e [1,2] would be a unit 1 tile wide, 2 tiles tall.)style
is how the GameBoard accesses the sprite.Assets can be kind of annoying. You have to load them up before you start trying to draw them.
var woman = new Image();
var grassland = new Image();
woman.src = '../assets/characters/woman.png';
grassland.src = '../assets/terrain/grassland_a.png';
var assets = {
woman: woman,
grass_a: grassland
};
var GameBoard = require('../index');
var canvas = document.getElementById('gameCanvas');
var gameBoard = new GameBoard({
canvas: canvas,
tiles: {},
tileSize: 16,
width: 10,
height: 10,
assets: assets // providing the actual Image(s) here.
});
The GameBoard will be accessing your assets by its style
attribute.
For example, if unit.style
is 'woman'
, the GameBoard will search through its assets
hash for GameBoard.assets['woman']
, which will reference your sprite!
You'll have to run them locally, as testlingci is having issues. No matter!
just run:
npm test
Which will spit out a URL for you to visit in your favourite browser!
http://localhost:51927/__testling?show=true
FAQs
simple canvas wrapper for visualizing output from game engines
The npm package gameboard receives a total of 7 weekly downloads. As such, gameboard popularity was classified as not popular.
We found that gameboard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.