Jump to content

What's the point in creating a seperate variable to contain all the game functions?


Recommended Posts

In the game "Monster Wants Candy," I see this in the source code, and I was wondering why this was done. I've tried doing this myself but keep failing.

This is what I mean:

var Candy = {};
Candy.Boot = function(game){};
Candy.Boot.prototype = {
	preload: function(){
		// preload the loading indicator first before anything else
		this.load.image('preloaderBar', 'img/loading-bar.png');
	create: function(){
		// set scale options
		this.input.maxPointers = 1;
		this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
		this.scale.pageAlignHorizontally = true;
		this.scale.pageAlignVertically = true;
		// start the Preloader state

(source: https://github.com/EnclaveGames/Monster-Wants-Candy-demo/blob/gh-pages/src/Boot.js)


var gameWidth = 800, gameHeight = 600;

var game = new Phaser.Game(gameWidth, gameHeight, Phaser.AUTO), 
BootState = function () {},
gameOptions = {
	playSound: true,
	playMusic: true

BootState.prototype = {
	preload: function () {
		this.game.load.image('loadingbar', 'assets/images/loadingbar.png');
		this.game.load.image('logo', 'assets/images/logo2.png');
		this.game.load.script('LoadState', 'js/gamestates/LoadState.js');
		this.game.load.script('pollyfill', 'js/lib/pollyfill.js');
		this.game.load.script('utils', 'js/lib/utils.js');

	create: function () {

		game.renderer.renderSession.roundPixels = true;

		this.game.state.add('LoadState', LoadState);

this.game.state.add('BootState', BootState);



I also note that I don't take "Game" as an argument in my game state functions, unlike Monster Wants Candy which has the argument "game" in it's bootstate.


Have I been doing something wrong? I'm following most of the tutorials and example code I've seen so far, though I am aware those may not always be good examples of best practice.

Thanks in advance for replies and sorry for the long post. I'm a bit of a JS and Phaser noob, I'm mainly just aiming to learn good practice with this project.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...