Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RetroFont to RenderTexture problem #6924

Open
jjcapellan opened this issue Oct 16, 2024 · 0 comments
Open

RetroFont to RenderTexture problem #6924

jjcapellan opened this issue Oct 16, 2024 · 0 comments

Comments

@jjcapellan
Copy link
Contributor

Version

  • Phaser Version: +3.85.00
  • Operating system: Debian 11
  • Browser: Chrome v128.0.6613.84

Description

Bad rendering occurs when a BitmapText obtained from a RetroFont object is drawn into a RenderTexture.
The problem only occurs when these conditions are met:

  1. The font uses a configuration offset other than 0.
  2. pixelart == true

Example Test Code

const FONT = "font1";

class MainScene extends Phaser.Scene {
    constructor() {
        super('mainScene');
    }

    preload() {
        // Needs offsetY = 831
        this.load.image("atlas", "imgs/invader.png");
        // Does not needs offset
        this.load.image("font7x10", "imgs/font7x10.png");
    }

    create() {
        const rt = this.add.renderTexture(0, 0, config.width, config.height)
            .setOrigin(0).setPosition(0, 0);

        this.createFont();
        const txt = this.make.bitmapText({
            font: FONT,
            text: "left  .......  a,left\n" +
                "right ....... d,right\n" +
                "shoot .......   space\n" +
                "or use gamepad"
        }, false)
            .setOrigin(0.5)
            .setTint(0xababab);

        const cx = rt.width / 2;
        const cy = rt.height / 2;
        rt.draw(txt, cx, cy);
    }

    createFont() {
        const config1 = {
            image: "atlas",
            width: 7,
            height: 10,
            chars: "0123456789abcdefghijklmnopqrstuvwxyz?!.,+-*%:= ",
            charsPerRow: 10,
            offset: { x: 0, y: 831 },
            spacing: { x: 1, y: 1 }
        };
        this.cache.bitmapFont.add(FONT, Phaser.GameObjects.RetroFont.Parse(this, config1));
    }
}

var config = {
    type: Phaser.WEBGL,
    backgroundColor: '0x121212',
    width: 320,
    height: 180,
    pixelArt: true,
    zoom: 2,
    scene: [MainScene],
    loader: {
        baseURL: "https://jjcapellan.github.io/phaser3-games/assets/",
        crossOrigin: "anonymous"
    }
};

var game = new Phaser.Game(config);

https://phaser.io/sandbox/uBEpvQ1j

Additional Information

This code works as expected in versions prior to 3.85.00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant