Jump to content

Nested scene functions?


Linzeestomp
 Share

Recommended Posts

Just toying around in Phaser 3 tonight and I got this to render totally fine without breaking any kind of scopes.
 

sceneName = new Phaser.Scene({
    key: 'sceneName',
    active: true,
    visible: true,
});
/**
 * sceneA functions
 */
sceneName.preload = function () {
    /**
     * Preload things here
     */
    console.log('Preloading scene...');
    this.load.image('logo', 'assets/logo.png');

    sceneName.create = function () {
        /**
         * Create things here
         */
        console.log(this.sys.settings.key, 'is alive and fine!');
        this.add.image(400, 300, 'logo');    

        sceneName.update = function () {
            /**
             * Update things here
             * 
             * CAREFUL: TOO MUCH CODE HERE = LAG!
             */
            console.log("Looping!");
        }
    };
};

 

I was a little surprised this worked without anything breaking--can anyone tell me if there is any inherent benefit of structuring my scenes like this ?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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