Sign in to follow this  
pete796

Game object

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");

 

Share this post


Link to post
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 :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.