Skip to content

Controller.paddingOverride default prevents Glow filter from calculating framebuffer padding #7242

@rannmann

Description

@rannmann

Version

  • Phaser Version: 4.0.0 RC6
  • Operating system: Linux
  • Browser: Chrome 133

Description

The Controller base class initializes paddingOverride to new Rectangle() (Controller.js:67), which is a zero-valued but truthy object.

The Glow filter overrides getPadding() and checks if (this.paddingOverride) before falling through to its own distance-based padding calculation (Glow.js:218). Since paddingOverride is always truthy, the Glow's distance * scale calculation never executes, and the framebuffer gets zero extra padding.

Expected: Glow extends beyond the sprite outline by distance pixels, following the alpha edges of the opaque pixels.

Actual: Glow is confined within the sprite's rectangular bounds and abruptly cuts off at the frame edges. The effect looks like a square gradient that stops at the sprite frame boundary.

Example Test Code

// Minimal reproduction
const config = {
    type: Phaser.AUTO,
    width: 400,
    height: 300,
    backgroundColor: '#2d2d2d',
    scene: {
        preload: function () {
            // Use any sprite with transparency (non-rectangular shape)
            this.load.image('star', 'https://labs.phaser.io/assets/sprites/star.png');
        },
        create: function () {
            const sprite = this.add.sprite(200, 150, 'star');
            sprite.enableFilters();
            const glow = sprite.filters.internal.addGlow(0xffff00, 4, 0, 1, false, 10, 16);

            // BUG: glow is clipped to sprite's rectangular bounds
            // WORKAROUND: uncomment the next line to fix it
            // glow.setPaddingOverride(null);
        }
    }
};

new Phaser.Game(config);

Additional Information

Root cause: Controller.js:67 sets this.paddingOverride = new Rectangle(). This zero-valued Rectangle is always truthy, so when Glow.getPadding() checks if (this.paddingOverride), it always takes the override path and returns zero padding instead of calculating distance * scale.

Workaround:

glow.setPaddingOverride(null);

Suggested fix: In Controller.js:67, change:

this.paddingOverride = new Rectangle();

to:

this.paddingOverride = null;

This lets filters with custom getPadding() implementations (Glow, Blur) fall through to their own padding logic by default. setPaddingOverride() can still be called explicitly when an override is desired.

This likely affects any filter that overrides getPadding() with a truthy check on paddingOverride.

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