espace

Phaser 3 scene see my previous scene in my active scene ???

Recommended Posts

hi,

curiosly when i use scene with phaser 3 like phaser 2 i see my previous scene behind my active scene... How do you do to have the same behaviour than phaser 2 : not see the previous scene in the active scene ?

console.clear();

var config = {
	type: Phaser.AUTO,
	width: 1480,
	height: 2270,
	backgroundColor: '#0d1018',
	physics: {
		default: "arcade",
		arcade: {
			gravity: { y: 200 }
		}
	},
	callbacks: {
		postBoot: function (game) {
			// In v3.15, you have to override Phaser's default styles
			game.canvas.style.width = '100%';
			game.canvas.style.height = '100%';
			}
		},
	};

	var state = {};
	var o = {};

	state.boot = {
		preload: function () {
			this.load.image("Enemy", "img/ball_enemy.png");
		},
		create: function () {
			o.enemy = this.add.sprite(740, 1135, 'Enemy');
			game.scene.start('main');
		},
	};

	state.main = {
		preload: function () {
			this.load.image("Player", "img/ball_enemy.png");
		},
		create: function () {
			 //here i see o.enemy in my state.main ???
                         o.player = this.add.sprite(140, 835, 'Player');
		},
	};

	var game = new Phaser.Game(config);
	game.scene.add('boot', state.boot, true);
	game.scene.add('main', state.main, true);
	game.scene.start('boot');

 

Share this post


Link to post
Share on other sites

Scene in Phaser 3 is not same as State in Phaser 2. If you don't stop one scene and start another, both scenes will be visible. So, you need to stop the previous scene (boot) before starting new scene(main).

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...

  • Recently Browsing   0 members

    No registered users viewing this page.