Using the Kiwi.Game Class

The Kiwi.Game class is the base class that is used when you create a new Game. It handles the initialization of all of the various individual game managers and holds the RAF (RequestAnimationFrame object) which is used for the game loop.

A Kiwi.js game will not run unless you have a Kiwi.Game object. Therefore it will be the first thing you need to create. Below is an example of how we create our games here at Kiwi.js!

The Kiwi.Game object takes four parameters. The first being the the ID of a DOM element that the game should use as its ‘container’. If you are targeting Cocoon then you don’t need to worry about this and can leave it blank. The second parameter is the name of the game that is being created. This can be anything you want. The third parameter is the state to load initially. This can either be the name of a state, but preferably this would be the state object itself. You can also pass null, which would mean that game does not switch to a state initially. Take a look at our Switching State tutorial for more information. The fourth parameter is the options parameter. This can be for any special options for the game. You’ll see that we have made a gameOptions object which holds multiple parameters.

The option parameter can be confusing if you do not know what it is intended for. We will cover what options a Kiwi.js Game can have.


Share the joy
Comments 2
  1. Robert Wildling

    Thank you for Kiwi – you guys are awesome! – May I just mention that the notation for the gameObject objects is wrong. Instead of

    var gameobjects = {
    gameobject.debug = ... // using gamobject again is wrong as is the equal operator

    something like this should be used (as in the first and probably all other tutorials):

    var gamobjects = {
    debug: … // get rid of gamobject and use a colon instead


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">