Skip to content
MEME-KING16 edited this page Oct 29, 2024 · 2 revisions

Getting Started

Setting up game engine

To start your game dev journey you need to set up a GameEngine instance the basic structure is provided below.

const game = new GameEngine({
    width: 800,
    height: 600,
    canvasId: 'gameCanvas',
  });

Adding sprites

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 });

Adding on key down events

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
   }
});

Adding realistic physics to your game

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()

Clone this wiki locally