HTML and CSS Reference
In-Depth Information
How to do it...
In order to create a 2D game framework that will handle the initialization, updating,
and rendering of assets, we must irst of all start by creating a new blank HTML5
canvas by following the steps previously mentioned. Once you have created a blank
canvas, we can then move onto creating the main JavaScript object responsible for
initializing the application. Begin by creating a new JavaScript object entitled Main
then input the following code into the Main object:
var frameTime = 0.0333;
var objectManager = null;
window.onload = function() {
new ObjectManager().InitObjectManager();
function Main() {
this.Initialise = function() {
return this;
The main object is responsible for kick-starting the application as well as determining
the desired frame rate, which will be fundamental to the application.
Next we create a new object, which will be responsible for handling each of the
objects within the game, that is, initializing and disposing of objects. Go ahead and
insert the following code:
function Object() {
this.x = 0;
this.y = 0;
this.z = 0;
this.InitObject = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
return this;
this.DisposeObject = function() {
Search WWH ::

Custom Search