NUGA Posted May 14, 2018 Share Posted May 14, 2018 let MainMenu = new Phaser.Class({ Extends: Phaser.Scene, initialize: function MyScene(config) { Phaser.Scene.call(this, config) }, preload: function () { this.load.image('Logo', 'assets/Logo.png'); }, create: function () { this.Logo = this.add.image(1024/2 ,100, 'Logo').setScale(2); Phaser.Display.Align.In.TopCenter(Logo); } }); I have this class (Scene?) that should represent my game's main menu. But, i want to pass to this class the game object that i'm creating in another file. In this case i want it merely to set my game's logo in top center using game.width and game.height as a way to make the logo be correctly placed with any size of the canvas. How can i do it? Link to comment Share on other sites More sharing options...
B3L7 Posted May 14, 2018 Share Posted May 14, 2018 In terms of passing an object you just make it the second parameter when you call the scene. this.scene.launch('MainMenu', passedObject); Then in the init function of receiving class you add the parameter to receive. init(data) { recievedObject = data; } Although for what you are looking to do you won't have to pass the object as game is accessible through the scenes system: this.sys.game It might just be easiest to use the width and height of the camera so: this.Logo = this.add.image(this.cameras.main.width / 2 ,100, 'Logo').setScale(2); samme 1 Link to comment Share on other sites More sharing options...
snowbillr Posted May 14, 2018 Share Posted May 14, 2018 FWIW in Phaser 3 you really shouldn't need to use the `game` object at all. Almost everything you do to interact with Phaser should be through your Scene's instance. B3L7 1 Link to comment Share on other sites More sharing options...
Recommended Posts