Appearance
RpgSceneMap
Example to use (in module)
ts
import { RpgServer, RpgModule, RpgServerEngine } from '@rpgjs/server'
@RpgModule<RpgServer>({
engine: {
onStart(engine: RpgServerEngine) {
const sceneMap = engine.sceneMap
sceneMap.createDynamicMap({
id: 'myid',
file: require('./tmx/town.tmx')
})
}
}
})
export default class RpgServerModuleEngine {}
API
Get maps
- Since: 4.0.0
- Method:
sceneMap.getMaps()
- Return:
RpgClassMap< RpgMap>[]
of RpgClassMap objects. - Example:
typescript
const maps = scene.getMaps();
console.log(maps);
// Output: [
// { file: 'maps/level1.tmx', id: 'level1', type: 'map' },
// { file: 'maps/level2.tmx', id: 'level1', type: 'map' },
// { file: 'maps/level3.tmx', id: 'level1', type: 'map' }
// ]
- Usage:
Returns an array of RpgClassMap objects that represent maps with static properties.
Create worlds dynamically
- Since: 3.0.0-beta.8
- Method:
sceneMap.createDynamicWorldMaps(world)
- Arguments:
- {
object
}world
. object is
- {
ts
{
id?: string
maps: {
id?: string
properties?: object
fileName: string;
height: number;
width: number;
x: number;
y: number;
}[],
onlyShowAdjacentMaps: boolean, // only for Tiled Map Editor
type: 'world' // only for Tiled Map Editor
}
(Optional: false
)
- Usage:
Loads the content of a .world
file from Tiled Map Editor into the map scene
Note, that if the map already exists (i.e. you have already defined an RpgMap), the world will retrieve the already existing map. Otherwise it will create a new map
Recover a world
- Since: 3.0.0-beta.8
- Method:
sceneMap.getWorldMaps(id)
- Arguments:
- {
string
}id
. world id (Optional:false
)
- {
- Usage:
Recover a world
Delete a world
- Since: 3.0.0-beta.8
- Method:
sceneMap.deleteWorldMaps(id)
- Arguments:
- {
string
}id
. world id (Optional:false
)
- {
- Usage:
Delete a world
Create a dynamic map
- Since: 3.0.0-beta.4
- Method:
sceneMap.createDynamicMap(mapData)
- Arguments:
- {
object | RpgMap | string
}mapData
. The same property as @MapData decorator (Optional:false
)
- {
- Return:
RpgMap
- Example:
ts
sceneMap.createDynamicMap({
id: 'myid',
file: require('./tmx/mymap.tmx')
})
And later, on the player:
ts
player.changeMap('myid')
since beta.8
ts
sceneMap.createDynamicMap(require('./tmx/mymap.tmx')) // id is "mymap"
- Usage:
Create a dynamic map
Since version 3.0.0-beta.8, you can just pass the path to the file. The identifier will then be the name of the file