Potion is a game library with simple and useful abstractions.
- Asset loader
- Input event handling
- Sound manager
- State manager
- Multi-layered canvas
- HiDPI monitor support
- Debugger for in game logging and switch toggling
Potion is compatible with CommonJS modules. Can be used with browserify, webpack and others. You can install it from npm.
npm install potion
There is also a built version you can download
<div class="container"></div>
var Potion = require('potion');
var app = Potion.init(document.querySelector('.container'), {
configure: function() {
app.resize(400, 400);
},
init: function() {
this.x = 0;
this.y = 0;
this.dx = 0;
this.dy = 0;
},
update: function(time) {
if (app.input.isKeyDown('w')) { this.dy -= 5000 * time; }
if (app.input.isKeyDown('d')) { this.dx += 5000 * time; }
if (app.input.isKeyDown('s')) { this.dy += 5000 * time; }
if (app.input.isKeyDown('a')) { this.dx -= 5000 * time; }
this.dx = this.dx + (0 - this.dx) * 8 * time;
this.dy = this.dy + (0 - this.dy) * 8 * time;
this.x += this.dx * time;
this.y += this.dy * time;
},
render: function() {
app.video.ctx.fillRect(this.x, this.y, 10, 10);
}
});