Merge pull request #1264 from thecodingmachine/UpdateShowHideLayer
Show/Hide Layer now unset collision and can show/hide all the layer in a group layer
This commit is contained in:
commit
ae9af56661
@ -54,6 +54,7 @@ WA.room.showLayer(layerName : string): void
|
|||||||
WA.room.hideLayer(layerName : string) : void
|
WA.room.hideLayer(layerName : string) : void
|
||||||
```
|
```
|
||||||
These 2 methods can be used to show and hide a layer.
|
These 2 methods can be used to show and hide a layer.
|
||||||
|
if `layerName` is the name of a group layer, show/hide all the layer in that group layer.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
@ -70,6 +71,9 @@ WA.room.setProperty(layerName : string, propertyName : string, propertyValue : s
|
|||||||
|
|
||||||
Set the value of the `propertyName` property of the layer `layerName` at `propertyValue`. If the property doesn't exist, create the property `propertyName` and set the value of the property at `propertyValue`.
|
Set the value of the `propertyName` property of the layer `layerName` at `propertyValue`. If the property doesn't exist, create the property `propertyName` and set the value of the property at `propertyValue`.
|
||||||
|
|
||||||
|
Note :
|
||||||
|
To unset a property from a layer, use `setProperty` with `propertyValue` set to `undefined`.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
WA.room.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');
|
WA.room.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');
|
||||||
|
@ -192,6 +192,10 @@ export class GameMap {
|
|||||||
return this.phaserLayers.find((layer) => layer.layer.name === layerName);
|
return this.phaserLayers.find((layer) => layer.layer.name === layerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public findPhaserLayers(groupName: string): TilemapLayer[] {
|
||||||
|
return this.phaserLayers.filter((l) => l.layer.name.includes(groupName));
|
||||||
|
}
|
||||||
|
|
||||||
public addTerrain(terrain: Phaser.Tilemaps.Tileset): void {
|
public addTerrain(terrain: Phaser.Tilemaps.Tileset): void {
|
||||||
for (const phaserLayer of this.phaserLayers) {
|
for (const phaserLayer of this.phaserLayers) {
|
||||||
phaserLayer.tileset.push(terrain);
|
phaserLayer.tileset.push(terrain);
|
||||||
|
@ -1100,12 +1100,25 @@ ${escapedMessage}
|
|||||||
|
|
||||||
private setLayerVisibility(layerName: string, visible: boolean): void {
|
private setLayerVisibility(layerName: string, visible: boolean): void {
|
||||||
const phaserLayer = this.gameMap.findPhaserLayer(layerName);
|
const phaserLayer = this.gameMap.findPhaserLayer(layerName);
|
||||||
if (phaserLayer === undefined) {
|
if (phaserLayer != undefined) {
|
||||||
console.warn('Could not find layer "' + layerName + '" when calling WA.hideLayer / WA.showLayer');
|
phaserLayer.setVisible(visible);
|
||||||
return;
|
phaserLayer.setCollisionByProperty({ collides: true }, visible);
|
||||||
|
} else {
|
||||||
|
const phaserLayers = this.gameMap.findPhaserLayers(layerName + "/");
|
||||||
|
if (phaserLayers === []) {
|
||||||
|
console.warn(
|
||||||
|
'Could not find layer with name that contains "' +
|
||||||
|
layerName +
|
||||||
|
'" when calling WA.hideLayer / WA.showLayer'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < phaserLayers.length; i++) {
|
||||||
|
phaserLayers[i].setVisible(visible);
|
||||||
|
phaserLayers[i].setCollisionByProperty({ collides: true }, visible);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
phaserLayer.setVisible(visible);
|
this.markDirty();
|
||||||
this.dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMapDirUrl(): string {
|
private getMapDirUrl(): string {
|
||||||
|
Loading…
Reference in New Issue
Block a user