What line of code creates the canvas?

I’m trying to learn how to use the Game Scaling/Resizing Example (v3) but I’m not sure how to apply it to my existing game. I currently have two canvas elements. The one that is resizing is empty and the one that has all my objects is below it.

I have a hunch new Phaser.Game(config) is it but I don’t know how to change the code so that it works with my existing game.

var game = new Phaser.Game(config);

game.scene.add('Boot', MyGame.Boot, true);
//code below belongs to resizing/scaling example.  Code above is what I originally added to my game.
window.addEventListener('load', () => {
  const game = new Phaser.Game(config)....

Use only one new Phaser.Game(config), where the example has it.

Put your scenes in the config like scene: [MyGame.Boot, …].

Okay thanks I did that but I’m using a function that reassigns colors in my spritesheet and I’m getting “game is not defined” on lines where ‘game’ is used in that function.

This is one of the drawbacks when you are using someone else’s code.

Show that code?

You can also do

const game = new Phaser.Game(config)
window.game = game

if you want to match what you had before.

Okay that worked. I noticed you suggested that in the past after an internet search but I never thought of putting it inside that function.

I’m using the Palette Swapping example:

You can usually reach the global managers (anims, textures) in other ways:

2 Likes