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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
Mouse
=====
The Mouse object is used to read input from the mouse.
*Example*
```
// This example shows how to use a sprite
// as a mouse cursor. Since My Cursor is
// tagged "detached", it will be rendered
// in screen space, not in world space.
using SurgeEngine.Actor;
using SurgeEngine.Transform;
using SurgeEngine.Input.Mouse;
object "My Cursor" is "entity", "detached"
{
actor = Actor("My Cursor");
transform = Transform();
state "main"
{
transform.position = Mouse.position;
if(Mouse.buttonPressed("left"))
Console.print("left click");
}
fun constructor()
{
actor.zindex = 1.0;
}
}
```
Properties
----------
#### position
`position`: [Vector2](/engine/vector2) object, read-only.
The position of the mouse cursor, in screen space.
#### scrollUp
`scrollUp`: boolean, read-only.
Will be `true` at the frame the user scrolls up using the mouse wheel.
*Available since:* Open Surge 0.5.1
#### scrollDown
`scrollDown`: boolean, read-only.
Will be `true` at the frame the user scrolls down using the mouse wheel.
*Available since:* Open Surge 0.5.1
Functions
---------
#### buttonDown
`buttonDown(buttonName)`
Checks if a mouse button is currently being held down.
*Arguments*
* `buttonName`: string. One of the following: *"left"*, *"right"*, *"middle"*.
*Returns*
Returns `true` if the specified button is being held down.
#### buttonPressed
`buttonPressed(buttonName)`
Checks if a mouse button has just been pressed.
*Arguments*
* `buttonName`: string. One of the following: *"left"*, *"right"*, *"middle"*.
*Returns*
Returns `true` if the specified button has just been pressed (i.e., a click has just occurred).
*Example*
```
using SurgeEngine.Input.Mouse;
using SurgeEngine.Collisions.CollisionBall;
using SurgeEngine.Transform;
using SurgeEngine.Camera;
// Use the mouse cursor to click on any entity that has a collider.
// Setup: simply place this object on the level.
object "Entity Picker" is "awake", "entity"
{
transform = Transform();
collider = CollisionBall(8);
state "main"
{
transform.position = Camera.screenToWorld(Mouse.position);
collider.visible = true;
}
fun onOverlap(otherCollider)
{
if(Mouse.buttonPressed("left"))
Console.print("Clicked on " + otherCollider.entity.__name);
}
}
```
#### buttonReleased
`buttonReleased(buttonName)`
Checks if a mouse button has just been released.
*Arguments*
* `buttonName`: string. One of the following: *"left"*, *"right"*, *"middle"*.
*Returns*
Returns `true` if the specified button has just been released.
|