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



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 () {'loadingbar', 'assets/images/loadingbar.png');'logo', 'assets/images/logo2.png');'LoadState', 'js/gamestates/LoadState.js');'pollyfill', 'js/lib/pollyfill.js');'utils', 'js/lib/utils.js');

	create: function () {

		game.renderer.renderSession.roundPixels = true;
		Phaser.Canvas.setImageRenderingCrisp(;'LoadState', LoadState);'LoadState');
};'BootState', 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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.