Skip to content

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

@tiuvi

Description

@tiuvi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy