Jump to content

Game object


pete796
 Share

Recommended Posts

Hi,

Can someone explain the advantage of creating an object (veggies) and then attaching the game object to veggies ? 

In many examples, the game object is attached isn't attached to another object.

Example 1
var Veggies = Veggies || {};
Veggies.game = new Phaser.Game(480, 320, Phaser.AUTO);



Example 2
game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, "ph_game");

 

Link to comment
Share on other sites

Do you mean instead of your example 2?
I do not know why you should write "var Veggies = Veggies || {};" since there is no code before.
for Example 2 I would write:

const game = new Phaser....

It's just for reference globally. If "Veggies" could be a Sprite, it will have "this.game" so it's not necessary to assign it.

Were do you get it from? I think the context will be different.

regards :)

Link to comment
Share on other sites

var Veggies = Veggies || {};
Veggies.game = new Phaser.Game(480, 320, Phaser.AUTO);

This is a simple namespacing technique. The idea is to create a single distinct global variable and store properties there.

The conditional assignment is done when several scripts may need to modify the object but their execution order is unknown.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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