1

I’m encountering an issue with a custom dropdown in my Phaser 3 game. The dropdown works perfectly on iOS and web, but on Android (APK), the screen turns black when I attempt to display the dropdown list. The dropdown is created using the DOM and dynamically populated with options. Here’s how I’m adding the dropdown:

// Create a dropdown using HTML
const dropdown = document.createElement('select');
dropdown.style.position = 'absolute';
dropdown.style.zIndex = '1000';

const option1 = document.createElement('option');
option1.value = '1';
option1.text = 'Option 1';
dropdown.appendChild(option1);

const option2 = document.createElement('option');
option2.value = '2';
option2.text = 'Option 2';
dropdown.appendChild(option2);

document.body.appendChild(dropdown);
dropdown.addEventListener('change', (event) => {
  const selectedValue = (event.target as HTMLSelectElement).value;
  console.log('Selected Value:', selectedValue);
  if (selectedValue === '1') {
    console.log('Option 1 selected');
  } else if (selectedValue === '2') {
    console.log('Option 2 selected');
  }

my gameconfig looks like below

export class RobotGame extends Phaser.Game {
constructor() {
    super({
        type: Phaser.AUTO,
        scale: {
            width: Dimensions.designResolution.width,
            height: Dimensions.designResolution.height,
            mode: Phaser.Scale.NONE,
        },
        backgroundColor: "#000000",
        banner: false,
        zoom: 1,
        autoMobilePipeline: true,
        plugins: {
            global: [

            ],
            scene: [
                {
                    key: "rexGestures",
                    plugin: gestures,
                    mapping: "rexGestures",
                },
            ],
        },
        loader: {
            crossOrigin: "anonymous",
            baseURL: CDN_PATH,
        },
        parent: "DOMElementParent",
        dom: {
            createContainer: true,
        },
        render: {
            transparent: true,
            powerPreference: "high-performance",
            autoMobilePipeline: true,
        },
    });

    this.canvas.className = "game_canvas";

    SafeArea.getSafeAreaInsets().then((safeArea) => {
        this.bootGame(safeArea);
    });
}

private bootGame(safeArea: SafeAreaInsets): void {
    const ppi = window.devicePixelRatio;
    Dimensions.safeAreaInsets = {
        top: safeArea.insets.top * ppi,
        right: safeArea.insets.right * ppi,
        bottom: safeArea.insets.bottom * ppi,
        left: safeArea.insets.left * ppi,
    };

    this.scene.add("Boot", new Boot());
    this.scene.start("Boot");
}
  • using Phaser: 3
  • Capacitor : 6
  • @capacitor/android": “^6.0.0”

screenShot of dropdown looks like below

enter image description here

I suspect it might be related to DOM element rendering on Android. Any ideas or suggestions on debugging or fixing this?

6
  • Has it to do with the font-color or so? this doesn't seem to be a phaser error, or does the Error only appear it the phaser game is loaded? Asked differnetly does the html/dorpdown code work without the phaser game? Commented Dec 5, 2024 at 8:33
  • Yes, the HTML dropdown works fine on its own. However, when added to the Phaser canvas, it appears black when the dropdown is opened. This issue occurs only on Android, whereas it works fine on the web. Additionally, no specific styles, font colors, or background colors have been applied to the dropdown. Commented Dec 5, 2024 at 8:44
  • Maybe no Styles were set to the dropdown perse, but if styles were added, in generell to the HTML, or the parent Tag, these might cascade down, or simply from the Browser/Phones/Os current Theme, styles are passed on. These all effect the DOM. Are you using a CSS reset file/directive? Commented Dec 5, 2024 at 10:15
  • If it is no "styling"-issue, can you share some more relevant code. MRE go a long way. Commented Dec 6, 2024 at 5:43
  • Thank you for looking to it, but after a thorough observation, I found that the issue was not with Phaser or the HTML code but with the colour of the WebView on the Android system. Specifically, I had to go through the styles.xml file under res/values and change <item name="android:background">@android:color/black</item> to a more suitable colour to ensure the font and background matched. Commented Dec 16, 2024 at 13:30

2 Answers 2

0

Well some parts are missing, but let me assume, since the code-snippets leave alot of room for speculation, and I could reproduce this issue with the provide code (or maybe I'm missing something):

  1. The issue has to do something with styling of the html elements, and the browser / phone default theme (Dark-Theme or so). Since the selection is visible (the lila dot, but the text not)
  2. The used Dropdown is only on the html page, not connected with the Phaser game. (If this was intended, you would have to use this.add.dom link to documentation). This disconnect/overlay, might cause issues.

Sidenote phaser html-elements (canvas/domContainer) should not be css-styled, since this can cause display issues.

Tip:
If you are willing to use phaser - plugins you could check this plugin(s), the offer UI-Controlls, "inside of phaser", and this would look the same on each platform (more or less, atleast more consitent than HTML-controls)

Sign up to request clarification or add additional context in comments.

Comments

0

I found that the issue was related WebView background color set in the Android system.

Root Cause:

The WebView background color was set in the "styles.xml" file under res/values/.

By default, it was set to @android:color/black, which caused poor contrast between the text and background, making it difficult to view.

Solution:

Navigate to your Android project’s res/values/styles.xml file.

Look for the line:

<item name="android:background">@android:color/black</item>

Change it to a more suitable color, such as gray or white, to improve text visibility. For example:

<item name="android:background">@android:color/white</item>

Save the changes and Run the app and verify that the text is now properly visible.

By modifying the WebView background color in styles.xml, I was able to fix the issue. I hope this helps others facing a similar problem!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.