A lightweight JavaScript game engine
git clone git://soophie.de/game-engine
blob: 1a4dada5c6dfd7345bd4a09d766e04d3fe3f069a (1012 bytes)[doc][blame][raw]
1
# game-engine2
A lightweight JavaScript Game Engine3
<br>4
<br>6
## Example7
<br>9
```javascript10
import GameEngine from '...';12
const {Game, Surface, Shape} = GameEngine;13
```14
<br>16
```javascript17
class Entity extends Surface {19
constructor(x, y) {20
super(x, y, new Shape.Rect(60, 60));21
}23
update() {24
// ...25
}27
render(g) {28
const {x, y, shape} = this;29
g.fillRect(x, y, shape.width, shape.height);30
}32
}33
```34
<br>36
```javascript37
class ExampleGame extends Game {39
constructor() {40
super(window.innerWidth, window.innerHeight);41
this.bindEvent(window, 'resize');42
this.entity = new Entity(100, 100);43
}45
onresize() {46
this.resize(window.innerWidth, window.innerHeight);47
}49
update() {50
this.entity.update();51
}53
render(g) {54
super.render(g);55
this.entity.render(g);56
}58
}60
const game = new ExampleGame();61
game.start();63
document.body.appendChild(game.canvas);64
```