File: camera.md

package info (click to toggle)
surgescript 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,200 kB
  • sloc: ansic: 15,748; sh: 61; javascript: 38; makefile: 13
file content (116 lines) | stat: -rw-r--r-- 3,036 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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.

!!! tip "Detached entities"

    Entities tagged *"detached"* do not follow the camera. They are rendered in screen space, not in world space. This is useful for creating HUD elements (*Heads-Up Display*). Read more about [entities](/engine/entity).

*Example*

```cs
// 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. Tip: use [lateUpdate()](/engine/entity) if you need to change it.

*Example*
```cs
using SurgeEngine.Camera;
using SurgeEngine.Player;

object "My Simple Camera" is "awake", "entity"
{
    fun lateUpdate()
    {
        player = Player.active;
        Camera.position = player.transform.position;
    }
}
```

#### 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.