phaserjs / phaserjs/phaser

Fix flickering bug by ensuring game canvas dimensions are even numbers in Phaser config

Open
#7,164 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
40.3k
Forks
7.2k
PR merge metrics
No merged PRs in 30d

Description

A rendering flicker occurred when the Phaser game canvas width or height was an odd number. This issue was caused by subpixel rendering and rounding errors when the canvas size had fractional pixels. The solution was to adjust the game configuration to force both the width and height to be even numbers by subtracting 1 if they were odd. This ensures smoother rendering and prevents visual artifacts during gameplay.

If you want it more formal or detailed, just tell me!

     const config = {
            type: Phaser.AUTO,
            width: window.innerWidth % 2 === 1 ? window.innerWidth - 1 : window.innerWidth ,
            height: window.innerHeight % 2 === 1 ? window.innerHeight - 1 : window.innerHeight ,
           
            
            backgroundColor: '#2d2d2d',
            parent: gameRef.current,
            pixelArt: true,
            physics: {
                default: 'arcade',
                arcade: {
                    gravity: { y: 0 },
                    debug: false
                }
            },
            scene: [firstScene, ...Object.values(othersScenes)], // Aquí va el nombre de tu clase de escena

            // --- AÑADE ESTA SECCIÓN ---
            plugins: {
                global: [{
                    key: 'rexVirtualJoystick',
                    plugin: rexvirtualjoystickplugin, // El nombre de la clase del plugin
                    start: true
                }]
            }
        };

https://phaser.discourse.group/t/roundpixels-is-causing-jittering-with-cameras-main-startfollow/11880/8

I saw the solution in this post, I would like to know what is happening since my game is currently small and there should be no problems.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named. Start by locating the Phaser game configuration shown in the issue and inspect how its canvas dimensions are calculated; done means odd or fractional viewport dimensions no longer produce flickering or visual artifacts during rendering.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.