File: sensor.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 (79 lines) | stat: -rw-r--r-- 2,420 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
Sensor
======

A Sensor is used to detect collisions with bricks. Due to performance optimizations, passable bricks (or bricks that are too far off camera) can't be sensed.

*Example*
```cs
using SurgeEngine.Actor;
using SurgeEngine.Collisions.Sensor;

object "SensorToy" is "entity"
{
    actor = Actor("SensorToy");
    sensor = Sensor(0, -25, 1, 50); // a vertical sensor

    state "main"
    {
        if(sensor.status != null)
            Console.print("Got a brick of type " + sensor.status);
    }

    fun constructor()
    {
        sensor.visible = true;
    }
}
```



Factory
-------

#### Sensor

`Collisions.Sensor(x, y, width, height)`

Spawns a new Sensor with the specified dimensions and having its top-left corner located at position (*x*, *y*) relative to the parent object. A Sensor is either a vertical or a horizontal bar that is 1-pixel thin. Both *width* and *height* must be positive integers, and at least one of them must be equal to 1.

*Arguments*

* `x`: number. The x-position of the top-left corner of the sensor, relative to the parent object.
* `y`: number. The y-position of the top-left corner of the sensor, relative to the parent object.
* `width`: number. The width of the sensor, in pixels. Must be a positive integer.
* `height`: number. The height of the sensor, in pixels. Must be a positive integer.

*Returns*

A Sensor with the specified parameters.


Properties
----------

#### status

`status`: string | `null`, read-only.

The type of the brick colliding with the sensor (either *"solid"* or *"cloud"*). If the sensor isn't colliding with a brick, or if it's disabled, its status will be `null`.

#### visible

`visible`: boolean.

Should the sensor be rendered? Useful for debugging. Defaults to `false`.

#### enabled

`enabled`: boolean.

Indicates whether the sensor is enabled or not. Defaults to `true`.

#### layer

`layer`: string.

The layer of this sensor. This property assumes one of the following values: `"default"`, `"green"` or `"yellow"`. If it's set to `"default"`, then all non-passable bricks and [brick-like objects](/engine/brick) are sensed. If it's set to `"green"`, then all non-passable bricks and brick-like objects are sensed, except the ones in the yellow layer. Conversely, if it's set to `"yellow"`, then all non-passable bricks and brick-like objects are sensed, except the ones in the green layer.

*Available since:* Open Surge 0.6.1