物理引擎

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ù)操作移動
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容