Hey! i want to repeat the form in my scene like in the example here Phaser - Examples - Form Input, but when i try to add the dom element using hmtl from the cache this.add.dom (500, 800) .createFromCache (‘nameform’), then the domContainer in the game variable remains empty and the form itself does not appear, although I can find the loaded html in the cache. What could be the problem?
here is my scene code:
export default class BootScene extends Phaser.Scene {
constructor() {
super('Boot')
}
preload() {
this.load.setBaseURL(document.location.href)
this.load.html('nameform', 'src/assets/loginform.html');
}
create() {
var text = this.add.text(10, 10, 'Please login to play', { color: 'white', fontFamily: 'Arial', fontSize: '32px ' });
var element = this.add.dom(500, 800).createFromCache('nameform');
element.addListener('click');
element.on('click', function(event) {
if (event.target.name === 'loginButton') {
var inputUsername = this.getChildByName('username');
var inputPassword = this.getChildByName('password');
if (inputUsername.value !== '' && inputPassword.value !== '') {
this.removeListener('click');
this.scene.tweens.add({ targets: element.rotate3d, x: 1, w: 90, duration: 3000, ease: 'Power3' });
this.scene.tweens.add({
targets: element,
scaleX: 2,
scaleY: 2,
y: 700,
duration: 3000,
ease: 'Power3',
onComplete: function() {
element.setVisible(false);
}
});
text.setText('Welcome ' + inputUsername.value);
} else {
this.scene.tweens.add({
targets: text,
alpha: 0.1,
duration: 200,
ease: 'Power3',
yoyo: true
});
}
}
});
this.tweens.add({
targets: element,
y: 300,
duration: 3000,
ease: 'Power3'
});
}
added in the game config:
dom: {
createContainer: true
},