Can't get arcade physics to work alongside matter physics

I have a game seemingly needing both matter and arcade physics. I appear to have the matter physics working fine, but anything arcade physics related errors out.

My game config is like so:

var config = {
max: {
	width: 1920,
	height: 1080
},
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: window.innerWidth * window.devicePixelRatio,
height: window.innerHeight * window.devicePixelRatio

},
backgroundColor: 0xFFFFFF,
antialias: true,
renderer: Phaser.CANVAS,
type: Phaser.WEBGL,
physics: {
	
	arcade: {
		debug:true,
		gravity: { y:0 }
	},
	matter: {
		debug: true,
		gravity: { y:0 },
		debugShowBody: true,
		debugBodyColor: 0x0000ff
	}
	
},
scene: [ BootScene, GameScene ]
}


const game = new Phaser.Game(config);

then in my init:

	init () {
	this.game.physics.startSystem(Phaser.Physics.ARCADE);	
}

which errors with “Cannot read property ‘startSystem’ of undefined”.
If I remove the init line and assume phaser 3 automatically initializes arcade physics if in the config, if I invoke “physics” anywhere in my create section like:

this.physics.moveTo(thisUnit, attackX, attackY, 240, 1000);	

I get: “Cannot read property ‘moveTo’ of undefined”

Physics config must be in the scene config.

http://phaser.io/examples/v3/view/physics/multi/arcade-and-matter

I see. Could you assist with the proper syntax of this given my scenario? I’ve tried this:

var config = {
max: {
	width: 1920,
	height: 1080
},
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: window.innerWidth * window.devicePixelRatio,
height: window.innerHeight * window.devicePixelRatio

},
backgroundColor: 0xFFFFFF,
antialias: true,
renderer: Phaser.CANVAS,
type: Phaser.WEBGL,

scene: {
	BootScene, 
	GameScene,
	physics: {
		default: "matter",
		arcade: {
			debug:true,
			gravity: { y:0 }
		},
		matter: {
			debug: true,
			gravity: { y:0 },
			debugShowBody: true,
			debugBodyColor: 0x0000ff
		}	
	}
}
}

But it isnt working…

class GameScene extends Phaser.Scene {
  constructor () {
    super({
      key: 'game',
      physics: {
        arcade: {
          debug: true,
          gravity: { y: 0 }
        },
        matter: {
          debug: true,
          gravity: { y: 0 },
          debugShowBody: true,
          debugBodyColor: 0x0000ff
        }
      }
    });
  }
}

var config = {
  // …
  scene: [BootScene, GameScene]
};
1 Like

I sort of got it working, but I had to remove my BootScene to do so, and my line:

init () {
game.physics.startSystem(Phaser.Physics.ARCADE);	
}

errors with “Cannot read property ‘startSystem’ of undefined”

What was the problem?

That’s Phaser 2 code, it won’t work.

It would not progress past the boot scene, but it didnt throw any errors either, so I just removed it as I dont need it at this stage of development for my game yet anyway. Do I even need to initialize the arcade physics in phaser 3? How does it differ from startSystem? I can’t find a proper snippet to use in place of this…

You don’t need to use anything like startSystem().