File: camera.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (101 lines) | stat: -rw-r--r-- 2,646 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Camera
======

The Camera object can be used to control what content (in world space) is rendered to the screen. The Camera is represented by a 2-dimensional point in world space that is mapped to the center of the screen.

> **HUD elements**
>
> Objects tagged as *"detached"* do not follow the camera. They are not in world space, but in screen space. This is useful for creating HUD elements.

*Example*

```
// Import the Camera object
using SurgeEngine.Camera;

// Reading the Camera status
// This object prints the position of the camera at every second
object "Camera Status" is "awake", "entity"
{
    state "main"
    {
        if(timeout(1))
            state = "print";
    }

    state "print"
    {
        Console.print(Camera.position);
        state = "main";
    }
}
```

Properties
----------

#### position

`position`: [Vector2](/engine/vector2) object.

The position of the camera in world space.

#### locked

`locked`: boolean, read-only.

Is the camera locked to a certain area in space? Defaults to `false`.

Functions
---------

#### lock

`lock(left, top, right, bottom)`

Locks the camera to a certain rectangular area in space. All coordinates are given in pixels and represent the boundaries of the rectangular area. They are such that `left` <= `right` and `top` <= `bottom`.

*Arguments*

* `left`: number. A x-coordinate in world space.
* `top`: number. A y-coordinate in world space.
* `right`: number. A x-coordinate in world space.
* `bottom`: number. A y-coordinate in world space.

#### unlock

`unlock()`

Unlocks the camera. If unlocked, the camera moves freely throughout the space.

#### worldToScreen

`worldToScreen(position)`

Converts `position` from world space to screen space. Screen coordinates are given in pixels. (0,0) is the top-left of the screen and ([Screen.width](/engine/screen#width),[Screen.height](/engine/screen#height)) is the bottom-right.

*Available since:* Open Surge 0.5.1

*Arguments*

* `position`: [Vector2](/engine/vector2) object. The position to be converted.

*Returns*

Returns a [Vector2](/engine/vector2) object corresponding to the converted coordinates.

#### screenToWorld

`screenToWorld(position)`

Converts `position` from screen space to world space. Screen coordinates are given in pixels. (0,0) is the top-left of the screen and ([Screen.width](/engine/screen#width),[Screen.height](/engine/screen#height)) is the bottom-right.

*Available since:* Open Surge 0.5.1

*Arguments*

* `position`: [Vector2](/engine/vector2) object. The position to be converted.

*Returns*

Returns a [Vector2](/engine/vector2) object corresponding to the converted coordinates.