Camera follow lerp is framerate-dependent
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript
- Lĩnh vực
- game-dev, performance
Hướng nghiên cứu
Bắt đầu với src/cameras/2d/Camera.js và các nhánh follow và deadzone trong preRender(), sau đó chạy ví dụ một tệp được cung cấp để tái hiện các settle times khác nhau ở 30Hz và các tần số làm mới cao hơn. Cập nhật hành vi lerp bằng frame delta hiện có và thêm các test cho thấy follow timing tương đương ở các frame rate khác nhau; hoàn tất khi camera ổn định với cùng một tốc độ bất kể tần số rendering.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Camera follow smoothing (startFollow with lerpX/lerpY < 1) is framerate dependent. The lerp factor is applied once per rendered frame in Camera.preRender, so the camera's tracking speed scales with the display's refresh rate: a game tuned on a 60Hz monitor pans exactly 2x faster on a 120Hz display and ~2.4x faster at 144Hz, and slower under any frame drop. The same applies to the deadzone follow path, which uses the same per-frame lerp.
With high-refresh displays now common, the same build feels noticeably different from machine to machine, and there is no way to compensate from user code since the lerp is applied inside preRender where no delta is exposed.
Example Test Code
Runnable single file, no build step. Two identical games with identical startFollow lerp values — the only difference is fps: { limit: 30 } on the second one. Every 3 seconds the follow target teleports 500px and each game measures the wall-clock time the camera takes to close to within 10px.
Expected if follow were framerate independent: both games report the same settle time. Actual: the 30fps game takes exactly twice as long as a 60Hz display (~1560ms vs ~780ms), and on a 120Hz display the uncapped game halves again (~390ms).
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
<style>body { display: flex; gap: 8px; background: #000; margin: 0; padding: 8px; }</style>
</head>
<body>
<div id="uncapped"></div>
<div id="capped"></div>
<script>
const LERP = 0.08;
const JUMP = 500;
const SETTLE_THRESHOLD = 10;
function makeGame(parent, fps, label) {
let target;
let text;
let jumpedAt = 0;
let dir = 1;
let settled = true;
new Phaser.Game({
parent,
width: 480,
height: 320,
backgroundColor: '#1d2b53',
fps,
scene: {
create() {
for (let x = -800; x <= 1600; x += 100) {
this.add.rectangle(x, 160, 4, 320, 0x3a4a83);
}
target = this.add.rectangle(240, 160, 24, 24, 0xffffff);
this.cameras.main.startFollow(target, false, LERP, LERP);
text = this.add.text(10, 10, label, { font: '14px monospace' }).setScrollFactor(0);
this.time.addEvent({
delay: 3000,
loop: true,
callback: () => {
target.x += dir * JUMP;
dir *= -1;
jumpedAt = performance.now();
settled = false;
}
});
},
update() {
if (!settled && Math.abs(this.cameras.main.midPoint.x - target.x) < SETTLE_THRESHOLD) {
settled = true;
text.setText(label + '\nsettle time: ' + Math.round(performance.now() - jumpedAt) + ' ms');
}
}
}
});
}
makeGame('uncapped', undefined, 'uncapped (display refresh rate)');
makeGame('capped', { limit: 30 }, 'fps limit: 30');
</script>
</body>
</html>
Additional Information
Root cause: src/cameras/2d/Camera.js, preRender() — the follow branch applies a constant factor once per render:
sx = Linear(sx, fx - originX, lerp.x);
sy = Linear(sy, fy - originY, lerp.y);
plus the four analogous Linear calls in the deadzone branch. More renders per second means more lerp steps per second.
Proposed fix (I'm happy to submit a PR with tests): normalize the per-frame factor to a 60fps reference using the frame delta, which is already reachable inside preRender without any signature changes:
var fpsFactor = this.scene.sys.game.loop.delta / (1000 / 60);
sx = Linear(sx, fx - originX, 1 - Math.pow(1 - lerp.x, fpsFactor));
sy = Linear(sy, fy - originY, 1 - Math.pow(1 - lerp.y, fpsFactor));
- Ngôn ngữ chính
- JavaScript
- Star
- 40.7k
- Fork
- 7.2k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phaserjs/phaser
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Type definition for TilemapLayer.getTileAt is wrongCó thể đã có người làm @hkbughk đã nhận 34 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Shader.preDestroy leaks its ShaderQuad's vertex buffer and VAO on every create/destroy cycle (4.2.1)Có thể đã có người làm @k1epg01ng129-eng đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Black opaque background on transparent Phaser.Text textures in Phaser 4.2.1 on older iOS WebGLCó thể đã có người làm @SamuelMalmfors đã nhận 14 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
phaserjs/phaser#7392 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của phaserjs/phaser
Issue tương tự
-
enhancement ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
DCGM/semant-demo#708 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
agents area: runtime automation chore cli consistency dependencies developer-experience difficulty: easy documentation enhancement good first issue help wanted hygiene json-output priority: P3 starters tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Client codegen: an import repeated in an impl file is emitted twice, and the browser rejects the moduleCó thể đã có người làm @MalithaPrabhashana đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
jaseci-labs/jac#10756 ·
Maintainer thường phản hồi trong vòng 1 ngày