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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//Initialise the Kiwi Game. var gameOptions = { renderer: Kiwi.RENDERER_WEBGL, width: 800, height: 600 } var game = new Kiwi.Game('content', 'myGame', null, gameOptions); //Add all the States we are going to use. game.states.addState( Loading ); game.states.addState( Intro ); game.states.addState( Play ); game.states.switchState( "Loading" ); |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
var gameoptions = { //Defines how many logs Kiwi should return. debug : Kiwi.DEBUG_ON, //Or Kiwi.DEBUG_OFF //Used to determine how, and also which, various managers should boot. deviceTarget : Kiwi.TARGET_BROWSER, //Or Kiwi.TARGET_COCOON //Which type of renderer should be used. renderer : Kiwi.RENDERER_CANVAS, // Or Kiwi.RENDERER_WEBGL //Width of the Stage width : 800, //Height of the Stage height : 600, //How Kiwi should scale the Stage/Container. Default is 'no-scaling'. scaleType : Kiwi.Stage.SCALE_NONE, //Also accepts "SCALE_STRETCH" or "SCALE_FIT" //Plugins that are to used with your game. //An array of Strings, with each string being the name of Plugin to use. //If blank, no plugins will be used. plugins : ['SaveGame', 'InAppPurchase'], //A function that should be called when the game just finished the boot stage. //This method is executed just before the loop is executed for the first time. bootCallback : functionToBeCalled }; |
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
}
`
Thanks!
Thanks for that! Don’t know how that slipped by