0% found this document useful (0 votes)
7 views1 page

Tiled Layers - WorkAdventure Documentation

The document provides an overview of the Inbound API and Map Scripting API, detailing functions for managing layers in a map, including retrieving layer boundaries and accessing layers by name. It emphasizes the need to import the 'Scripting API Extra' library for certain functions and includes code examples for using these utilities. Additionally, it mentions that layers can be nested and indexed by name, with specific methods to obtain boundaries for individual or multiple layers.

Uploaded by

raziq.brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Tiled Layers - WorkAdventure Documentation

The document provides an overview of the Inbound API and Map Scripting API, detailing functions for managing layers in a map, including retrieving layer boundaries and accessing layers by name. It emphasizes the need to import the 'Scripting API Extra' library for certain functions and includes code examples for using these utilities. Additionally, it mentions that layers can be nested and indexed by name, with specific methods to obtain boundaries for individual or multiple layers.

Uploaded by

raziq.brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Map Building Admin User Developer Tutorials Login Get Started Search ctrl K

Inbound API

Map Scripting API Map Scripting API Extended utility functions Tiled Layers
Return a Map of all layers

Variables Get boundaries of a layer

Events Tiled Layers Get boundaries of several layers

Api Reference

Camera IMPORTANT

Chat To use these functions, you need to import the "Scripting API Extra" library.

Controls

Event Return a Map of all layers


Map Editor API Layers can be nested in group layers.
Metadata
The getLayersMap() function returns a map of all layers in a uni-dimensional map.
Navigation

Player Layers are renamed: if they are in a group layer, the name of the group layer is prepended with a "/" as a separator.

Players Layers are indexed by name.

Room
import {getLayersMap} from '@workadventure/scripting-api-extra';
Sound

Start const layers = await getLayersMap();

State // Access a layer directly by name


UI const mylayer = layers.get('my_layer');

Deprecated Functions // Iterate over all layers


for (const layer of layers.values()) {
Extended utility functions
// ...
Tiled Layers }

Tiled Properties

Svelte Get boundaries of a layer


Variables findLayerBoundaries returns the boundaries of a given layer as an object with properties: { top: number, left: number, right: number,
Scripting Internals bottom: number }

Numbers are expressed in "tiles", not pixels.

findLayerBoundaries(layer: ITiledMapTileLayer): {
top: number;
left: number;
right: number;
bottom: number;
}

Example:

import {getLayersMap, findLayerBoundaries} from '@workadventure/scripting-api-extra';


import {ITiledMapTileLayer} from "@workadventure/tiled-map-type-guard/dist/ITiledMapTileLayer";

const layers = await getLayersMap();

const layer = layers.get("my_layer") as ITiledMapTileLayer;

const boundaries = findLayerBoundaries(layer);


console.log('Top:' , boundaries.top);
console.log('Left:' , boundaries.left);
console.log('Bottom:' , boundaries.bottom);
console.log('Right:' , boundaries.right);

Get boundaries of several layers


If you are looking for the boundaries of several layers at once, you can use the findLayersBoundaries variant.

findLayersBoundaries(layers: ITiledMapTileLayer[]): {
top: number;
left: number;
right: number;
bottom: number;
}

It will return a square containing all the tiles of all the layers passed in parameters.

Edit this page

Previous Next
« Extended Utility Functions Tiled Properties »

Docs Need help ? Follow us

Map Building Book a demo Linkedin


Admin Discord Twitter
Developer GitHub Facebook

Copyright © 2024 workadventu.re - All Rights Reserved

You might also like