Well… this wasn’t it… I prepared example with more of code (i actually copied things that I work on, and cut things that I think don’t matter in this case), mind You that I tried to debug this problem a lot, I googled everything about inputs and scenes, I read scenes guide (from devlogs) and I’m quite upset:
app.js:
import OverworldScene from “./scenes/OverworldScene”;
import MainMenuScene from “./scenes/MainMenuScene”;const config = {
type: Phaser.AUTO,
width: window.innerWidth,
height: window.innerHeight,
roundpixels: true,
pixelArt: true,
physics: {
default: ‘arcade’,
arcade: {
gravity: { y: 0 }
}
},
scene: [
MainMenuScene,
OverworldScene
]
};const game = new Phaser.Game(config);
MainMenuScene.js:
import Menu from “…/classes/MenuClass”;
import TextBoxScene from “…/scenes/TextBoxScene”;class MainMenu extends Menu {
constructor (x, y, scene) { super(scene, x, y); Menu.call(this, x, y, scene); }; confirm() { };
};
class MainMenuScene extends Phaser.Scene {
constructor() {
super({
key: ‘MainMenuScene’
});
this.background = null,
this.bottomTextBox = null,
this.keys = {};
}
preload() {} create() { //this.input.setGlobalTopOnly(false); // <== I tried even this... this.keys.keyEnter = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ENTER); this.keys.keyW = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W); this.keys.keyS = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S); this.scene.add('TextBoxScene', new TextBoxScene, true); let textBoxScene = this.scene.get('TextBoxScene'); textBoxScene.events.on('textBoxReady', () => { textBoxScene.bottomTextBox.init(); textBoxScene.bottomTextBox.addText('Tekst, tekst, tekst duuuuuuzoo tekstuuuu i dluuuuuugie wyrazy, ale duuuuuzo tekstu, no tak duzo tekstu, ze niewiemy co z nim zrobic.'); }); this.scene.bringToTop('TextBoxScene'); } update() { }
};
export default MainMenuScene;
TextBoxScene:
class TextBoxScene extends Phaser.Scene {
constructor(test) {
super({
key: ‘TextBoxScene’,
active: true,
});
this.topTextBox = null,
this.bottomTextBox = null,
this.customTextBox = null,
this.keys = {};
//this.inactive = false;
}
preload() {
}
create() {
this.keys.keyEnter = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ENTER);
this.keys.keyW = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W);
this.keys.keyS = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S);
}
update() {
if (Phaser.Input.Keyboard.JustDown(this.keys.keyEnter)) {
if (this.bottomTextBox.externals.visible) {
this.bottomTextBox.addText(‘a’);
} else if (this.topTextBox.externals.visible) {
this.topTextBox.addText(‘a’);
}
}
if (Phaser.Input.Keyboard.JustDown(this.keys.keyW)) {} if (Phaser.Input.Keyboard.JustDown(this.keys.keyS)) { } } textBoxBackground(posX, posY, width, height, allocation) { }
}
export default TextBoxScene;
I’m using the ES6, if all this code isn’t enough for someone with more knowledge than me to debug it I will send whole code to anyone willing to help me. You may notice that I already add TextBoxScene with “this.scene.add” with 3rd argument as true (just like in a guide).
What I noticed is that if I comment mapping keys in create of MainMenuScene (this lines: “this.keys.keyEnter = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ENTER);”) then I works… so maybe I shouldnt map keys like that? ← this may be a good lead to answering why my controls don’t work