Phaser Matter Collision Plugin
1 .使用這個插件,開發(fā)更加便捷
2 .https://blog.xiiigame.com/2018-10-14-Phaser2%E5%AE%98%E7%BD%91%E5%AE%9E%E4%BE%8B%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/#distance_to_pointer 計算物理角速度,兩個物體連線的角度
3 .組和自身的碰撞關(guān)系
通過物理引擎
1 .可以實現(xiàn)慣性這種表現(xiàn)形式,比如車根據(jù)鼠標(biāo)按鍵走,停下的時候需要一定的時間。感覺幾乎所有的都需要加這個東西。確實真實了不少,按鍵停下就立馬停止的一點也不好玩。
2 .它里面推薦的是matter.
this.matter.world.setBounds(0, 0, 3200, 600);
this.cameras.main.setBounds(0, 0, 3200, 600);
//設(shè)置物理世界的邊界
this.player = this.matter.add.sprite(1600, 200, 'ship')
.setFixedRotation()
.setFrictionAir(0.05)
.setMass(30);
this.cameras.main.startFollow(this.player, false, 0.2, 0.2);
//給主角加上物理屬性
if (this.cursors.left.isDown)
{
this.player.thrustBack(0.2);
// this.player.flipX = true;
}
else if (this.cursors.right.isDown)
{
this.player.thrust(0.1);
// this.player.flipX = false;
}
if (this.cursors.up.isDown)
{
this.player.thrustLeft(0.1);
}
else if (this.cursors.down.isDown)
{
this.player.thrustRight(0.1);
}
//主角根據(jù)操作移動