Get position of an object in Tile to set popUp Position

This commit is contained in:
DESKTOP-FMM8UI0\CLV 2021-03-09 17:07:14 +01:00
parent 70898a2f28
commit d29e0819f4
2 changed files with 16 additions and 8 deletions

View File

@ -167,6 +167,8 @@ export class GameScene extends ResizableScene implements CenterListener {
private playerName!: string;
private characterLayers!: string[];
private popUpElements : Map<number, DOMElement> = new Map<number, Phaser.GameObjects.DOMElement>();
private popUpX! : number;
private popUpY! : number;
constructor(private room: Room, MapUrlFile: string, customKey?: string|undefined) {
super({
@ -379,6 +381,13 @@ export class GameScene extends ResizableScene implements CenterListener {
}
if (layer.type === 'objectgroup' && layer.name === 'floorLayer') {
depth = 10000;
for (const object of layer.objects) {
if (object.name === 'myPopup') {
this.popUpX = Math.floor(object.x);
this.popUpY = Math.floor(object.y);
}
}
}
}
if (depth === -2) {
@ -734,6 +743,7 @@ export class GameScene extends ResizableScene implements CenterListener {
if (newValue === undefined || newValue === false || newValue === '') {
iframeListener.sendLeaveEvent(oldValue as string);
} else {
console.log("je passe dans zone");
iframeListener.sendEnterEvent(newValue as string);
}
});
@ -743,13 +753,11 @@ export class GameScene extends ResizableScene implements CenterListener {
private listenToIframeEvents(): void {
iframeListener.openPopupStream.subscribe((openPopupEvent) => {
const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message);
let html = `<div class="nes-container with-title is-centered">
${escapedMessage}
</div>`;
const domElement = this.add.dom(150, 150).createFromHTML(html);
domElement.scale = 0;
const domElement = this.add.dom(this.popUpX, this.popUpY).createFromHTML(html);
domElement.scale = 1;
domElement.setClassName('popUpElement');
this.tweens.add({
targets : domElement ,

View File

@ -82,8 +82,8 @@
"type":"",
"visible":true,
"width":162.815914588373,
"x":77.4042872633247,
"y":61.1226958044874
"x":76.1933509951528,
"y":167.886910114979
}],
"opacity":1,
"type":"objectgroup",
@ -101,7 +101,7 @@
"value":"script.js"
}],
"renderorder":"right-down",
"tiledversion":"1.3.3",
"tiledversion":"1.4.3",
"tileheight":32,
"tilesets":[
{
@ -119,6 +119,6 @@
}],
"tilewidth":32,
"type":"map",
"version":1.2,
"version":1.4,
"width":10
}