J4ck
July 21, 2020, 10:02pm
1
Hi, how can i enable arcade physics system in the scene. I know this can be enabled in the game config when the Phaser game is initialize eg:
var config = {
physics: {
default: ‘arcade’,
arcade: {
debug: false,
gravity: { y: 0 }
}
}
};
But how can I enable physics after game is initialize from the scene?
Thanks.
samme
July 21, 2020, 11:57pm
3
You add the same object (physics.arcade
) to the scene config.
J4ck
July 22, 2020, 12:42am
4
Can physics be enabled in the preload() or create function()? What is wrong here?
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'phaser-example',
scene: {
preload: preload,
create: create
}
};
new Phaser.Game(config);
function preload ()
{
this.load.scenePlugin({
key: 'ArcadePhysics',
sceneKey: 'physics',
url: Phaser.Physics.Arcade.ArcadePhysics
});
this.load.image('block', 'assets/sprites/block.png');
}
function create ()
{
window.g = this;
this.physics.world.gravity.y = 60;
var player = this.physics.add.sprite(400, 0, 'block');
this.physics.world.enable(player);
}
samme
July 22, 2020, 2:44pm
5
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: {
preload: preload,
create: create,
physics: {
arcade: {
debug: true,
gravity: { y: 200 }
}
},
}
};