`Controller.paddingOverride` default prevents Glow filter from calculating framebuffer padding

Đang mở
#7,242 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
game-dev

Hướng nghiên cứu

Bắt đầu với phần khởi tạo paddingOverride trong src/filters/Controller.js và so sánh với Glow.getPadding() trong src/filters/Glow.js. Sử dụng bản tái hiện tối thiểu với một sprite trong suốt để xác minh rằng padding của Glow được tính từ khoảng cách theo mặc định, trong khi setPaddingOverride() vẫn cho phép ghi đè rõ ràng. Được xem là hoàn tất khi glow mở rộng vượt ra ngoài các cạnh của sprite mà không bị cắt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của phaserjs/phaser

Tất cả issue của phaserjs/phaser

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.