added documentation for Focusable Zones

This commit is contained in:
Hanusiak Piotr 2021-12-14 12:03:05 +01:00
parent 0f1378c069
commit 960c247b20
15 changed files with 101 additions and 31 deletions

86
docs/maps/camera.md Normal file
View File

@ -0,0 +1,86 @@
{.section-title.accent.text-primary}
# Working with camera
## Focusable Zones
It is possible to define special regions on the map that can make the camera zoom and center on themselves. We call them "Focusable Zones". When player gets inside, his camera view will be altered - focused, zoomed and locked on defined zone, like this:
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/0_focusable_zone.png" alt="" />
</div>
### Adding new **Focusable Zone**:
1. Make sure you are editing an **Object Layer**
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/1_object_layer.png" alt="" />
</div>
2. Select **Insert Rectangle** tool
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/2_rectangle_zone.png" alt="" />
</div>
3. Define new object wherever you want. For example, you can make your chilling room event cosier!
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/3_define_new_zone.png" alt="" />
</div>
4. Edit this new object and click on **Add Property**, like this:
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/4_click_add_property.png" alt="" />
</div>
5. Add a **bool** property of name *focusable*:
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/5_add_focusable_prop.png" alt="" />
</div>
6. Make sure it's checked! :)
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/6_make_sure_checked.png" alt="" />
</div>
All should be set up now and your new **Focusable Zone** should be working fine!
### Defining custom zoom margin:
If you want, you can add an additional property to control how much should the camera zoom onto focusable zone.
1. Like before, click on **Add Property**
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/4_click_add_property.png" alt="" />
</div>
2. Add a **float** property of name *zoom_margin*:
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/7_add_zoom_margin.png" alt="" />
</div>
2. Define how much (in percentage value) should the zoom be decreased:
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/8_optional_zoom_margin_defined.png" alt="" />
</div>
For example, if you define your zone as a 300x200 rectangle, setting this property to 0.5 *(50%)* means the camera will try to fit within the viewport the entire zone + margin of 50% of its dimensions, so 450x300.
- No margin defined
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/no_margin.png" alt="" />
</div>
- Margin set to **0.35**
<div class="px-5 card rounded d-inline-block">
<img class="document-img" src="images/camera/with_margin.png" alt="" />
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -51,6 +51,12 @@ return [
'markdown' => 'maps.website-in-map',
'editUrl' => 'https://github.com/thecodingmachine/workadventure/edit/develop/docs/maps/website-in-map.md',
],
[
'title' => 'Camera',
'url' => '/map-building/camera.md',
'markdown' => 'maps.camera',
'editUrl' => 'https://github.com/thecodingmachine/workadventure/edit/develop/docs/maps/camera.md',
],
[
'title' => 'Variables',
'url' => '/map-building/variables.md',

View File

@ -793,7 +793,10 @@ export class GameScene extends DirtyScene {
const focusable = zone.properties?.find((property) => property.name === "focusable");
if (focusable && focusable.value === true) {
const zoomMargin = zone.properties?.find((property) => property.name === "zoom_margin");
this.cameraManager.enterFocusMode(zone, Number(zoomMargin?.value));
this.cameraManager.enterFocusMode(
zone,
zoomMargin ? Math.max(0, Number(zoomMargin.value)) : undefined
);
break;
}
}

View File

@ -150,15 +150,10 @@
"y":0
},
{
"height":128,
"height":146.081567555252,
"id":9,
"name":"chillZone",
"properties":[
{
"name":"display_name",
"type":"string",
"value":"Chilling Room"
},
{
"name":"focusable",
"type":"bool",
@ -167,14 +162,14 @@
{
"name":"zoom_margin",
"type":"float",
"value":0.5
"value":3
}],
"rotation":0,
"type":"zone",
"visible":true,
"width":192,
"x":32,
"y":96
"y":77.9184324447482
},
{
"height":416,
@ -194,7 +189,7 @@
{
"name":"zoom_margin",
"type":"float",
"value":0
"value":0.35
}],
"rotation":0,
"type":"zone",
@ -203,26 +198,6 @@
"x":736,
"y":32
},
{
"height":66.6667,
"id":12,
"name":"",
"rotation":0,
"text":
{
"fontfamily":"Sans Serif",
"halign":"center",
"pixelsize":11,
"text":"Step inside to focus on the chilling zone",
"valign":"center",
"wrap":true
},
"type":"",
"visible":true,
"width":155.104,
"x":52.6352863978128,
"y":125.784444486216
},
{
"height":66.6667,
"id":13,
@ -286,7 +261,7 @@
"y":0
}],
"nextlayerid":39,
"nextobjectid":14,
"nextobjectid":18,
"orientation":"orthogonal",
"properties":[
{