startFollow , produces vibration in the game

未关闭
#7,174 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
javascript
领域
game-dev

调研方向

首先检查 Phaser 的 camera startFollow 入口点,并使用链接的视频以及 issue 中描述的低速、放大设置重现报告的振动。确定预期的原生跟随行为,并验证无需进行报告中所述的手动位置取整,摄像机移动也不再振动。

由索引模型根据 Issue 内容生成。

描述

In this example, I test startFollow at a slow speed and zoomed in, which is how it looks best.
Then I comment out startFollow and use my function, which I have enabled in a prerender.

https://cell1.tiuvi.com:1029/mp4/startFollowVibration.mp4

In this video, I test my function, which is my least favorite part: having to round the player's x and y positions.
Also, the camera speed needs to be slightly slower than the player's.
https://cell1.tiuvi.com:1029/mp4/newFunctionStartFollow.mp4

If this function could be done natively, it might perform better.

        state.events.on('prerender', () => {
                
                const velocity = state.global.player.body.velocity;

                const speedPlayerPx = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);

                // Accedemos a la cámara principal y al jugador
                const cam = state.cameras.main;
                const player = state.global.player;

                const px = player.x;
                const py = player.y;

                const centerMapX = cam.width / 2
                const centerMapY = cam.height / 2

                const playerPositionX = px + centerMapX;
                const playerPositionY = py + centerMapY

                const cameraPositionX = cam.scrollX + centerMapX;
                const cameraPositionY = cam.scrollY + centerMapY;

                const marginWidth = (cam.width * (cam.zoom * cam.zoom) / 2) * 0.2

                const marginHeight = (cam.height * (cam.zoom * cam.zoom) / 2) * 0.2


                let moviment = speedPlayerPx === 0 ? 1 : speedPlayerPx * 0.7
                if(moviment < 1){
                    moviment = 1;
                }

                let newCamX = cam.scrollX;
                let newCamY = cam.scrollY;

                if ((cameraPositionX + marginWidth) > playerPositionX) {

                    newCamX = cam.scrollX - moviment;

                } else if ((cameraPositionX + cam.width - marginWidth) < playerPositionX) {

                    newCamX = cam.scrollX + moviment;
                }


                if ((cameraPositionY + marginHeight) > playerPositionY) {

                    newCamY = cam.scrollY - moviment;

                } else if ((cameraPositionY + cam.height - marginHeight) < playerPositionY) {


                    newCamY = cam.scrollY + moviment;
                }

                if (cam.scrollX === newCamX && cam.scrollY === newCamY) {
                    return;
                }


                player.x = Math.round(px)
                player.y = Math.round(py)

                newCamX = Math.round(newCamX);
                newCamY = Math.round(newCamY);


                cam.scrollX = newCamX;
                cam.scrollY = newCamY;
            });
主要语言
JavaScript
星标
40.7k
派生
7.2k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

phaserjs/phaser 的其他 Issue

查看 phaserjs/phaser 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。