Camera follow lerp is framerate-dependent
Mantenedores costumam responder em até 3 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 72/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- javascript
- Domínio
- game-dev, performance
Direção de pesquisa
Comece por src/cameras/2d/Camera.js e pelos branches follow e deadzone de preRender(), depois execute o exemplo de arquivo único fornecido para reproduzir os diferentes tempos de settle em 30Hz e em taxas de atualização mais altas. Atualize o comportamento de lerp usando o frame delta disponível e adicione testes mostrando um timing de follow equivalente entre diferentes taxas de quadros; considera-se concluído quando a câmera se estabiliza na mesma velocidade independentemente da frequência de renderização.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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));
- Linguagem predominante
- JavaScript
- Estrelas
- 40.7k
- Forks
- 7.2k
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de phaserjs/phaser
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 3 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 3 dias
-
Type definition for TilemapLayer.getTileAt is wrongTalvez já em andamento @hkbughk assumiu há 34 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 3 dias
-
Shader.preDestroy leaks its ShaderQuad's vertex buffer and VAO on every create/destroy cycle (4.2.1)Talvez já em andamento @k1epg01ng129-eng assumiu há 32 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
Mantenedores costumam responder em até 3 dias
-
Black opaque background on transparent Phaser.Text textures in Phaser 4.2.1 on older iOS WebGLTalvez já em andamento @SamuelMalmfors assumiu há 14 dias. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
phaserjs/phaser#7392 · 1 comentário ·
Mantenedores costumam responder em até 3 dias
Todas as issues de phaserjs/phaser
Issues semelhantes
-
topg.org functionalityAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
needs:triage
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
Mantenedores costumam responder em até 1 dia
-
fix(readme): skills.sh badge says 'resource not found' and the skills.sh link is a 404; skills.sh still lists the old name tdk-skillsTalvez já em andamento @bfs2021 assumiu hoje. Abertaarea: ci area: docs badge bug chore cleanup consistency developer-experience difficulty: easy docs documentation good first issue hygiene journey: first-visit links priority: P3 skills user-journey
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
flisk-sh/flisk-skills#39 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 1 dia
-
Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Ionaru/easy-markdown-editor#656 ·