partey_workadventure/docs/maps/api-camera.md

51 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2021-11-23 17:39:45 +01:00
{.section-title.accent.text-primary}
2022-01-14 12:38:16 +01:00
2021-11-23 17:39:45 +01:00
# API Camera functions Reference
2022-01-14 12:38:16 +01:00
### Start following player
```javascript
WA.camera.followPlayer(smooth: boolean): void
```
Set camera to follow the player. Set `smooth` to true for smooth transition.
### Set spot for camera to look at
```javascript
WA.camera.set(
x: number,
y: number,
width?: number,
height?: number,
lock: boolean = false,
smooth: boolean = false,
): void
```
Set camera to look at given spot.
Setting `width` and `height` will adjust zoom.
Set `lock` to true to lock camera in this position.
Set `smooth` to true for smooth transition.
### Listen to camera updates
2021-11-23 17:39:45 +01:00
```
WA.camera.onCameraUpdate(): Subscription
2021-11-23 17:39:45 +01:00
```
Listens to updates of the camera viewport. It will trigger for every update of the camera's properties (position or scale for instance). An event will be sent.
2021-11-23 17:39:45 +01:00
The event has the following attributes :
* **x (number):** coordinate X of the camera's world view (the area looked at by the camera).
* **y (number):** coordinate Y of the camera's world view.
* **width (number):** the width of the camera's world view.
* **height (number):** the height of the camera's world view.
**callback:** the function that will be called when the camera is updated.
Example :
```javascript
const subscription = WA.camera.onCameraUpdate().subscribe((worldView) => console.log(worldView));
2022-01-03 10:36:23 +01:00
//later...
2022-01-13 10:44:06 +01:00
subscription.unsubscribe();