Skip to content

Commit 81ad432

Browse files
committed
imp: add more Control.md docs
1 parent f712627 commit 81ad432

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

docs/scripting/app/App.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ Creates and returns a node of the specified name.
6565

6666
### `.control(options)`
6767

68-
Gets a controller for handling user input. See [Input](/docs/scripting/app/Input.md) for more info.
69-
68+
Gives you control to listen for inputs and modify things like camera position. See [Control(/docs/scripting/app/Control.md) for more info.
7069

7170
#### `.configure(fields)`
7271

docs/scripting/app/Input.md renamed to docs/scripting/app/Control.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,27 @@
22

33
## `app.control(options)`: Control
44

5-
The `app.control()` method gives you access to user inputs like keyboard and mouse. It's the primary way to create interactive experiences. You can have multiple active controls, and they are prioritized.
5+
The `app.control()` method gives you access to user inputs like keyboard and mouse and gives you control over the camera etc. It's the primary way to create interactive experiences.
66

77
```javascript
88
// Get a control object
9-
const controls = app.control({ priority: 1 })
9+
const control = app.control()
1010

1111
// The app will be cleaned up automatically, but if you need to manually release control:
12-
controls.release()
12+
control.release()
1313
```
1414

15-
**Options**
15+
### Buttons
1616

17-
* `priority` (Number): A number that determines the order of input processing. Higher numbers have higher priority. Defaults to `0`. Player controls usually have a low priority, so scripts can override them.
18-
* `onButtonPress` (Function): A callback for any button press. `(prop, text) => {}`. `prop` is the button property name (e.g. `keyW`), `text` is the character for the key. Return `true` to consume the event.
19-
20-
21-
### Button Events
22-
23-
You can listen to press and release events for keyboard keys and mouse buttons.
17+
Listen to press and release events for keyboard keys and mouse buttons.
2418

2519
```javascript
2620
// Listen for 'W' key press and release
27-
controls.keyW.onPress = () => { console.log('W pressed') }
28-
controls.keyW.onRelease = () => { console.log('W released') }
21+
control.keyW.onPress = () => { console.log('W pressed') }
22+
control.keyW.onRelease = () => { console.log('W released') }
2923

3024
// Listen for left mouse button
31-
controls.mouseLeft.onPress = () => { console.log('Left mouse button pressed') }
25+
control.mouseLeft.onPress = () => { console.log('Left mouse button pressed') }
3226
```
3327

3428
Each button object has the following properties:
@@ -50,7 +44,7 @@ Access pointer (mouse) information.
5044
```javascript
5145
// Get pointer delta every frame
5246
app.on('update', () => {
53-
const pointerDelta = controls.pointer.delta
47+
const pointerDelta = control.pointer.delta
5448
if (pointerDelta.x !== 0 || pointerDelta.y !== 0) {
5549
console.log('Pointer moved:', pointerDelta.x, pointerDelta.y)
5650
}
@@ -70,9 +64,33 @@ Get mouse scroll wheel changes.
7064

7165
```javascript
7266
// The value is the scroll delta for the current frame.
73-
const scrollDelta = controls.scrollDelta.value
67+
const scrollDelta = control.scrollDelta.value
7468
```
7569

7670
* `scrollDelta.value` (Number): The scroll delta for the current frame.
7771
* `scrollDelta.capture` (Boolean): If `true`, consumes the scroll event.
7872

73+
### Camera
74+
75+
Lets you read and also modify the camera position if needed.
76+
77+
By default the camera information is read-only, set `write` to true when you want to take over control.
78+
79+
```jsx
80+
control.camera.write = true
81+
control.camera.position.y = 4
82+
```
83+
84+
* `camera.position` (Vector3): The position of the camera in world space.
85+
* `camera.quaternion` (Quaternion): The quaternion rotation of the camera in world space.
86+
* `camera.rotation` (Euler): The euler rotation (radians) of the camera in world space.
87+
* `camera.zoom` (Number): Third person zoom value, eg how far back the camera is from its position.
88+
* `camera.write` (Boolean): Set this to `true` if you want to modify the camera in any way.
89+
90+
91+
### Screen
92+
93+
Gives you the dimensions of the screen in pixels, useful when positioning UI.
94+
95+
* `screen.width` (Number): The width of the screen in px.
96+
* `screen.height` (Number): The height of the screen in px.

0 commit comments

Comments
 (0)