I am working on an adventure game with Phaser 3 that is a choose your own adventure style. I'm using the DOM element for HTML elements to make it accessible to text to speech technologies. I had been using a logo image for the game as a place holder image, it is a jpg file. The scenes pass from one to the next and the elements in the DOM changed until I started to change backgrounds. There are different places to explore; forests, mountains, etc. After I added a forest image, a jpg that is the same size as the logo image, when I click the button to go to a different scene, the background image does change but the DOM element contents do not. Each scene preloads and creates the background for that scene individually. I'm wondering why it's doing this and how to fix it so I can add in the different backgrounds? I am including the code for the scene that uses the forest background. If that's not enough information, please let me know so I can provide what is needed.
import { CST } from "../CST";
import Phaser, { AUTO } from "phaser";
export class RaidCombatScene extends Phaser.Scene {
constructor() {
super({
key: CST.SCENES.RAIDCOMBAT
})
}
init(){
}
preload(){
this.load.html('raid', './assets/CoH/quests/RaidCombat.html');
this.load.image("forestbattle", "./assets/forestbattle.jpg");
}
create(){
//create background
let background = this.add.image(0, 0, "forestbattle").setOrigin(0);
background.setScale(2.2, 2.355);
var layout = this.add.dom(-5,545).createFromCache('raid');
layout.setDepth(1);
layout.addListener('click');
layout.on('click', () => {
if (event.target.name === 'cover') {
}
if (event.target.name === 'fleet') {
this.scene.start(CST.SCENES.RAIDSUCCESS);
this.scene.stop();
}
})
}
}
The game variable code:
var game = new Phaser.Game({
type: Phaser.AUTO,
width:1000,
height: 800,
parent: 'phaser-game',
dom:{
createContainer: true
},
scene:[
// all imported scenes
],
})
The HTML code for the DOM element:
<!-- HTML Document -->
<style>
body{
color: #ffffff;
margin: 0;
padding: 0;
}
.box {
height: 250px;
width: 1000px;
position: absolute;
background: rgb(0, 0, 0);
text-align: center;
}
.textBox{
overflow-x: hidden;
overflow-y: auto;
word-wrap: normal;
}
.textBox::-webkit-scrollbar {
width:10px;
}
.textBox::-webkit-scrollbar-track {
box-shadow: inset;
-webkit-box-shadow:inset 0 0 6px rgba(227,218,201,0.3);
border-radius:5px;
}
.textBox::-webkit-scrollbar-thumb {
box-shadow: inset;
border-radius:5px;
-webkit-box-shadow: inset 0 0 6px wheat;
}
</style>
<div class="box" style="border: 4px white solid; display: flex;">
<div class="textBox" style="width: 75%; display:flex; align-items:center; justify-content: center;">
<button id="attack" name="attack">Attack</button>
<button id="cover" name="cover">Take Cover</button>
<button id="mug" name="mug">Mug</button>
<button id="items" name="items">Items</button>
</div>
<div style="display:flex; align-items:center; justify-content: center; width: 25%; border-left: 4px white solid; display: grid;">
<button id="flee" name="flee">Flee</button>
</div>
</div>