File: collisionbox.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (90 lines) | stat: -rw-r--r-- 1,763 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
CollisionBox
============

A CollisionBox is a special type of [Collider](/engine/collider) that takes the shape of a box. In 2D space, this is a rectangle with a specific width and height. All functions and properties of [Collider](/engine/collider) apply to this.

*Example*

```
using SurgeEngine.Actor;
using SurgeEngine.Collisions.CollisionBox;

object "CollisionDoll" is "entity"
{
    actor = Actor("CollisionDoll");
    collider = CollisionBox(32, 64); // width = 32px, height = 64px

    state "main"
    {
        collider.visible = true; // useful for debugging
    }

    fun onCollision(otherCollider)
    {
        Console.print("A collision has occurred.");
    }
}
```

Factory
-------

#### Collisions.CollisionBox

`Collisions.CollisionBox(width, height)`

Spawns a new CollisionBox with the specified dimensions, in pixels.

*Arguments*

* `width`: number. The width of the CollisionBox.
* `height`: number. The height of the CollisionBox.

*Returns*

A new CollisionBox with the specified dimensions.

Properties
----------

#### width

`width`: number.

The width of the CollisionBox, in pixels.

#### height

`height`: number.

The height of the CollisionBox, in pixels.

#### center

`center`: [Vector2](/engine/vector2), read-only.

The center of the CollisionBox, in world space.

#### top

`top`: number, read-only.

The y-coordinate of the top border of the CollisionBox, in world space.

#### right

`right`: number, read-only.

The x-coordinate of the right border of the CollisionBox, in world space.

#### bottom

`bottom`: number, read-only.

The y-coordinate of the bottom border of the CollisionBox, in world space.

#### left

`left`: number, read-only.

The x-coordinate of the left border of the CollisionBox, in world space.