Working on my own JS game engine

Posted on 26/01/2017

Not the first time I've had a go at building a reusable full engine from scratch. But it's something that one of these days I'm bound to settle on one and finish it. I know what I want from the engine, though I'm still hitting kinks when something doesn't quite work as well in practice as it did in my head. The engine itself is a JavaScript library primarily for HTML5 canvas games. It will be multi-platform with the help of Apache Cordova, which basically can put your HTML/CSS/JS/etc into a stand-alone web view that runs as a native app. It's pretty neat.


This project is influenced quite a bit by the Love2D project. I follow the same base structure of the user overwriting 3 main functions, these are; load(), update(dt) and draw(). The player creates these 3 functions and the engine loops through them automatically. The object system is more inline with that of GameMaker, where you create an object and it has a set group of variables that are used to automatically update the object "behind the scenes", such as; gravity, movement, physics and animation. Though on top of that, you can create normal "stripped" JS objects and put them into the system manually for more detailed control.

As you can see in the image, nothing is quite settled yet! I think most things will function like the GAME.textDraw() function does and accept all arguments as a JS object. I find this approach very neat and flexible; using one function and only filling in the bits I need. The alternative is the GAME.primitiveRectangle() function here, this can actually be assigned to a variable, but in this case I just want to draw it directly so it calls the method right after the rectangle is defined. But all it's parameters are fixed, and so it's not very flexible.

Will post more details on this as the engine grows up, it;s still a bubba right now. :)