To start your game dev journey you need to set up a GameEngine instance the basic structure is provided below.
GameEngine
const game = new GameEngine({ width: 800, height: 600, canvasId: 'gameCanvas', });
To add a basic sprite to your project you can use the code below.
//x and y are set to 1, 1 because of an error that occurs when set to 0 const player = new Sprite('https://www.example.com/sprite.png', { x: 1, y: 1 });
To add key down events its relatively similar to vanilla js.
game.onKeyDown('ArrowRight',()=>{player.x += 1})
Alternatively you can use the default js way of doing it
addEventListener("keydown", (event) => { if(event.key == 'ArrowRight') { player.x += 1 } });
In this example we will use the gravity of earth.
const gravity = new Physics({ gravity: 9.8 }); game.addPhysics(gravity); game.addSprite(player);
When you load up your game you will notice that there are no physics you have to start the game loop to get results
game.start()
There was an error while loading. Please reload this page.