Phaser 自带的Arcade虽然易用,但复杂的物理碰撞明显就不够用了,于是Matter等物理引擎还是不得不学的,以下是Matter物理体碰撞的一个插件,它省去了我们判别两个物理体相撞后哪个是gameObjectA和gameObjectB,实在是好用又省心,特推荐如下:
引入插件:
const config = {
// ...
physics: {
default: "matter"
},
// Install the scene plugin
plugins: {
scene: [
{
plugin: PhaserMatterCollisionPlugin, // The plugin class
key: "matterCollision", // Where to store in Scene.Systems, e.g. scene.sys.matterCollision
mapping: "matterCollision" // Where to store in the Scene, e.g. scene.matterCollision
}
]
}
};
const game = new Phaser.Game(config);
识别二个相撞体
const player = this.matter.add.sprite(0, 0, "player");
const trapDoor =