Class
MousePlugin
View sourceExtendsPlugin
Adds mouse input support to an App.
The plugin provides Mouse and MouseButtons resources in
the app’s default world. Use Mouse for pointer position and
movement, and MouseButtons for held, just-pressed, and
just-released MouseButton values.
These resources respond only to mouse input. Mouse exposes the
pointer position, movement, and wheel scrolling, while MouseButtons
exposes button transitions. Input from other pointer types is ignored.
WindowPlugin provides the typed pointer events consumed by this
plugin. In browser applications, add DOMWindowPlugin to bridge
native pointer events into those resources. This plugin requires
CorePlugin, ReflectPlugin, MathPlugin, and
WindowPlugin; register those dependencies before running the app.
Required plugins are not installed automatically.
Examples
import { App } from '@wimaengine/app'
import { CommandsPlugin } from '@wimaengine/command'
import { CorePlugin } from '@wimaengine/core'
import { MathPlugin } from '@wimaengine/math'
import { Mouse, MouseButton, MouseButtons, MousePlugin } from '@wimaengine/mouse'
import { ReflectPlugin } from '@wimaengine/reflect'
import { DOMWindowPlugin } from '@wimaengine/window-dom'
import { WindowPlugin } from '@wimaengine/window'
const app = new App()
.registerPlugin(new ReflectPlugin())
.registerPlugin(new CorePlugin())
.registerPlugin(new MathPlugin())
.registerPlugin(new CommandsPlugin())
.registerPlugin(new WindowPlugin())
.registerPlugin(new DOMWindowPlugin())
.registerPlugin(new MousePlugin())
app.run()
const world = app.getWorld()
const mouse = world.getResource(Mouse)
const buttons = world.getResource(MouseButtons)
if (mouse.moved()) {
console.log(mouse.position.x, mouse.position.y)
}
if (buttons.justPressed(MouseButton.Left)) {
console.log('left button pressed')
}Constructor
Methods
register(app: App): void
View sourceAdds Mouse and MouseButtons resources to the app’s
default world.
The resources expose current mouse position, movement, and button transitions from matching pointer events.
requires(): TypeId[]
View sourceReturns the plugin dependencies required by mouse input.
Register CorePlugin, ReflectPlugin, MathPlugin,
and WindowPlugin before this plugin. Registering
MousePlugin does not install them automatically.
