Skip to content

Commit

Permalink
docs: fix ex.Input namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Nov 26, 2024
1 parent 24e4a37 commit e82c0bd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions site/docs/02-fundamentals/04-architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const game = new ex.Engine({
height: 600, // the height of the canvas
canvasElementId: '', // the DOM canvas element ID, if you are providing your own
displayMode: ex.DisplayMode.FitScreen, // the display mode
pointerScope: ex.Input.PointerScope.Document // the scope of capturing pointer (mouse/touch) events
pointerScope: ex.PointerScope.Document // the scope of capturing pointer (mouse/touch) events
});
// call game.start, which is a Promise
game.start().then(function () {
Expand Down Expand Up @@ -241,7 +241,7 @@ var player = new ex.Actor(...);
// Enable pointer events for this actor
player.enableCapturePointer = true;
// subscribe to pointerdown event
player.on("pointerdown", function (evt: ex.Input.PointerEvent) {
player.on("pointerdown", function (evt: ex.PointerEvent) {
console.log("Player was clicked!");
});
// turn off subscription
Expand Down
4 changes: 2 additions & 2 deletions site/docs/11-input/10.1-input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Access [[Engine.input]] to see if any input is being tracked during the current
class Player extends ex.Actor {
public update(engine, delta) {
if (
engine.input.keyboard.isHeld(ex.Input.Keys.W) ||
engine.input.gamepads.at(0).getAxes(ex.Input.Axes.LeftStickY) > 0.5
engine.input.keyboard.isHeld(ex.Keys.W) ||
engine.input.gamepads.at(0).getAxes(ex.Axes.LeftStickY) > 0.5
) {
// implement the code to move the player forward
}
Expand Down
6 changes: 3 additions & 3 deletions site/docs/11-input/10.2-keyboard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ It is recommended that keyboard actions that directly effect actors be queried,
class Player extends ex.Actor {
public update(engine, delta) {
if (
engine.input.keyboard.isHeld(ex.Input.Keys.W) ||
engine.input.keyboard.isHeld(ex.Input.Keys.Up)
engine.input.keyboard.isHeld(ex.Keys.W) ||
engine.input.keyboard.isHeld(ex.Keys.Up)
) {
player._moveForward()
}

if (engine.input.keyboard.wasPressed(ex.Input.Keys.Right)) {
if (engine.input.keyboard.wasPressed(ex.Keys.Right)) {
player._fire()
}
}
Expand Down
20 changes: 10 additions & 10 deletions site/docs/11-input/10.3-pointer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ You can customize how pointer events are handled by setting the [[EngineOptions.
/// <reference path="../src/engine/excalibur.d.ts" />
// ---cut---
const game = new ex.Engine({
pointerScope: ex.Input.PointerScope.C
// ^|
pointerScope: ex.PointerScope.C
// ^|
});
```

Expand All @@ -147,8 +147,8 @@ You also have the option to handle _all_ pointer events in the browser window by
/// <reference path="../src/engine/excalibur.d.ts" />
// ---cut---
const game = new ex.Engine({
pointerScope: ex.Input.PointerScope.D
// ^|
pointerScope: ex.PointerScope.D
// ^|
});
```

Expand Down Expand Up @@ -241,15 +241,15 @@ Actors have the following **extra** events you can subscribe to:
## Checking the Pointer Type

The primary pointer can be a mouse, stylus, or single finger touch event. You
can inspect what type of pointer it is from the [[Input.PointerEvent|PointerEvent]] handled.
can inspect what type of pointer it is from the [[PointerEvent|PointerEvent]] handled.

```ts twoslash
// @include: ex
// ---cut---
engine.input.pointers.primary.on('down', function (pe: ex.Input.PointerEvent) {
if (pe.pointerType === ex.Input.PointerType.Mouse) {
engine.input.pointers.primary.on('down', function (pe: ex.PointerEvent) {
if (pe.pointerType === ex.PointerType.Mouse) {
ex.Logger.getInstance().info('Mouse event:', pe);
} else if (pe.pointerType === ex.Input.PointerType.Touch) {
} else if (pe.pointerType === ex.PointerType.Touch) {
ex.Logger.getInstance().info('Touch event:', pe);
}
});
Expand Down Expand Up @@ -280,8 +280,8 @@ know that there are _n_ touches on the screen at once.
// ---cut---
function paint(color: ex.Color) {
// create a handler for the event
return function (pe: ex.Input.PointerEvent) {
if (pe.pointerType === ex.Input.PointerType.Touch) {
return function (pe: ex.PointerEvent) {
if (pe.pointerType === ex.PointerType.Touch) {
engine.graphicsContext.drawRectangle(pe.worldPos, 5, 5, color);
}
};
Expand Down
12 changes: 6 additions & 6 deletions site/docs/11-input/10.4-gamepad.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ Once you have a reference to a gamepad you may listen to changes on that gamepad
- `axis` - Whenever an axis

```ts
engine.input.gamepads.on('connect', (ce: ex.Input.GamepadConnectEvent) => {
engine.input.gamepads.on('connect', (ce: ex.GamepadConnectEvent) => {
const newPlayer = CreateNewPlayer() // pseudo-code for new player logic on gamepad connection
console.log('Gamepad connected', ce)
ce.gamepad.on('button', (be: ex.GamepadButtonEvent) => {
if (be.button === ex.Input.Buttons.Face1) {
if (be.button === ex.Buttons.Face1) {
newPlayer.jump()
}
})

ce.gamepad.on('axis', (ae: ex.GamepadAxisEvent) => {
if (ae.axis === ex.Input.Axis.LeftStickX && ae.value > 0.5) {
if (ae.axis === ex.Axis.LeftStickX && ae.value > 0.5) {
newPlayer.moveRight()
}
})
Expand All @@ -78,11 +78,11 @@ engine.input.gamepads.enabled = true
// query gamepad on update
engine.on('update', function (ev) {
// access any gamepad by index
if (engine.input.gamepads.at(0).isButtonPressed(ex.Input.Buttons.Face1)) {
if (engine.input.gamepads.at(0).isButtonPressed(ex.Buttons.Face1)) {
ex.Logger.getInstance().info('Controller A button pressed')
}
// query individual button
if (engine.input.gamepads.at(0).getButton(ex.Input.Buttons.DpadLeft) > 0.2) {
if (engine.input.gamepads.at(0).getButton(ex.Buttons.DpadLeft) > 0.2) {
ex.Logger.getInstance().info('Controller D-pad left value is > 0.2')
}
})
Expand All @@ -108,7 +108,7 @@ engine.input.gamepads.enabled = true;
// query gamepad on update
engine.on('update', function(ev) {
// access any gamepad by index
const axisValue = = engine.input.gamepads.at(0).getAxes(ex.Input.Axes.LeftStickX));
const axisValue = = engine.input.gamepads.at(0).getAxes(ex.Axes.LeftStickX));
if (axisValue > 0.5) {
ex.Logger.getInstance().info('Move right', axisValue);
}
Expand Down
2 changes: 1 addition & 1 deletion site/docs/12-other/12-ui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const game = new ex.Engine({
* Specify pointer scope to ensure that excalibur won't capture the mouse input
* meant to be captured by HTML GUI
*/
pointerScope: ex.Input.PointerScope.Canvas,
pointerScope: ex.PointerScope.Canvas,
})

/**
Expand Down

0 comments on commit e82c0bd

Please sign in to comment.