gzaikun Posted November 19, 2015 Share Posted November 19, 2015 Hello everyone I have a problem with text phaser, when called from another prototype text suddenly disappeared. Boot.jsvar Core = { ver : '0.0.1',};var timeCheck;var text;Core.Boot = function(game) { this.game = game;};Core.Boot.prototype = { preload: function() { console.log('Boot preload - ok'); this.game.stage.backgroundColor = '#5c5c5c'; }, create: function() { console.log('Boot create - ok'); timeCheck = this.game.time.now; }, update: function() { if (game.time.now - timeCheck > 5000) { this.game.state.start('Preloader'); } }, loading: function() { game.load.onLoadStart.add(this.loadStart, this); game.load.onFileComplete.add(this.fileComplete, this); game.load.onLoadComplete.add(this.loadComplete, this); game.load.start(); }, loadStart: function() { text.setText("Loading ..."); }, fileComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) { text.setText( progress + "% - " + totalLoaded + " / " + totalFiles); }, loadComplete: function() { text.setText("Complete"); },}Preloader.jsCore.Preloader = function(game) { this.game = game;};Core.Preloader.prototype = { preload: function() { console.log('Preloader preload - ok'); text = this.game.add.text( 32, 32, 'Loading', { fill: '#ffffff' }); this.game.load.image('sky', 'assets/img/sky.png'); this.game.load.image('ground', 'assets/img/platform.png'); this.game.load.image('star', 'assets/img/star.png'); this.game.load.spritesheet('dude', 'assets/img/dude.png', 32, 48); test = new Core.Boot(); test.loading(); }, create: function() { console.log('Preloader create - ok'); }, update: function() { }} Link to comment Share on other sites More sharing options...
Cudabear Posted November 19, 2015 Share Posted November 19, 2015 You should add the text to the preload state instead of the boot state. When you change states, all the sprites that existed in the previous state are destroyed. This includes text! Link to comment Share on other sites More sharing options...
gzaikun Posted November 20, 2015 Author Share Posted November 20, 2015 Done, it works. [code edited above] So, whatever we do in preload: function() in every state, we have to rewrite again? Thank you @cudabear Link to comment Share on other sites More sharing options...
pog Posted November 20, 2015 Share Posted November 20, 2015 You normally only put a loading screen/text in your preloader.preload function and load the assets. If you want to change backgrounds and use more text you'd put it in the create function of the state the game is in. Link to comment Share on other sites More sharing options...
Recommended Posts