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

Buttons click area above the button when enabling fullscreen #6940

Open
djamn opened this issue Nov 12, 2024 · 0 comments
Open

Buttons click area above the button when enabling fullscreen #6940

djamn opened this issue Nov 12, 2024 · 0 comments

Comments

@djamn
Copy link

djamn commented Nov 12, 2024

Version

  • Phaser Version: 3.80.1
  • Operating system: Windows 10
  • Browser: Chrome

Description

I have the following phaser config

static canvas = {
        type: Phaser.AUTO,  // Which renderer to use
        width: 1000,         // Canvas width in pixels
        height: 480,        // Canvas height in pixels
        mode: Phaser.Scale.FIT,
        parent: "preview",   // ID of the DOM element to add the canvas to
        input: {
            activePointers: 10, // Support up to 10 simultaneous touches
        },
        physics: {
            default: 'arcade',       // Which physics engine to use
            arcade: {
                gravity: { y: 1200 },
                debug: false              // paint debug information (hitboxes) ee
            }
        },
    };

In my game i initalize buttons with the following code:

createMobileButtons() {
        const jumpbutton = this.createButton(config.canvas.width - 70, config.canvas.height - 70, 'jumpbutton', () => { jump(); isJump = true }, () => isJump = false, '#000', true, false)
        this.createButton(jumpbutton.x - jumpbutton.width - 35, config.canvas.height - 70, 'firebutton', () => { shoot(); isFire = true }, () => isFire = false, '#000', true, false)

        // Left + Right Button
        const leftButton = this.createButton(config.leftRightButtonPosition, config.canvas.height - 70, 'leftbutton', () => isMovingLeft = true, () => isMovingLeft = false, '#000', true, false);
        this.createButton(config.leftRightButtonPosition + leftButton.width, config.canvas.height - 70, 'rightbutton', () => isMovingRight = true, () => isMovingRight = false, '#000', true, false);
    }

    createButton(x, y, texture, onClick, onClickFinished = null, tintColor = null, showTintForPointerClick, showTintForPointerOver) {
        const button = this.add.sprite(x, y, texture).setInteractive();
        button.setScrollFactor(0);
        button.on('pointerdown', onClick);

        if (tintColor && showTintForPointerClick) {
            button.on('pointerdown', function () { this.setTint(tintColor); });
            button.on('pointerup', function () { this.clearTint(); });
            button.on('pointerout', function () { this.clearTint(); });
        }

        if (tintColor && showTintForPointerOver) {
            button.on('pointerover', function () { this.setTint(tintColor); });
            button.on('pointerout', function () { this.clearTint(); });
        }

        if (onClickFinished) {
            button.on('pointerup', onClickFinished);
            button.on('pointerout', onClickFinished)
        }

        return button;
    }

I have implemented my fullscreen like the following:

let canvas = level.sys.game.canvas;
   let fullscreen = level.sys.game.device.fullscreen;
canvas[fullscreen.request]();

(When i use game.scale.startFullscreen(); it does not fit on mobile devices)

However my issue: When I initalize my fullscreen, the area to click the button is above the actual position of the button. I dont know how to fix that, also adding game.scale.autoCenter = Phaser.Scale.CENTER_BOTH; does not help. In my image you can see where my mouse has to be to click the button
image

Thanks in advance

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