constructor(options?: Gravity2DPluginOptions)
View sourceCreates a 2D gravity plugin.
The optional gravity value is a Vector2. When omitted, it
defaults to (0, -980).
Class
ExtendsPlugin
Adds configurable 2D gravity to an App.
The plugin installs a Gravity2D resource initialized from the
configured Vector2, or (0, -980) by default. It applies that
acceleration to eligible bodies as the app updates. The plugin depends on
CorePlugin, ReflectPlugin, MathPlugin,
Movable2DPlugin, and NarrowPhase2DPlugin.
Pass a Vector2 in options.gravity to choose a different
acceleration. The vector is copied into the installed resource.
import { App } from '@wimaengine/app'
import { CorePlugin } from '@wimaengine/core'
import { Gravity2DPlugin } from '@wimaengine/gravity'
import { MathPlugin, Vector2 } from '@wimaengine/math'
import { Movable2DPlugin } from '@wimaengine/movable'
import { NarrowPhase2DPlugin } from '@wimaengine/narrowphase'
import { ReflectPlugin } from '@wimaengine/reflect'
new App()
.registerPlugin(new ReflectPlugin())
.registerPlugin(new CorePlugin())
.registerPlugin(new MathPlugin())
.registerPlugin(new Movable2DPlugin())
.registerPlugin(new NarrowPhase2DPlugin())
.registerPlugin(new Gravity2DPlugin({
gravity: new Vector2(0, -9.8)
}))
.run()constructor(options?: Gravity2DPluginOptions)Creates a 2D gravity plugin.
The optional gravity value is a Vector2. When omitted, it
defaults to (0, -980).
Configured Vector2 gravity vector.
The vector is copied into the installed Gravity2D resource when
the plugin is registered, so the resource has its own value.
register(app: App): voidInstalls configured 2D gravity in an app.
The installed Gravity2D contains a copy of
Gravity2DPlugin#gravity. Its acceleration is added to
eligible bodies as the app updates.
requires(): TypeId[]Returns the plugin dependencies required by 2D gravity.
The returned IDs identify CorePlugin, ReflectPlugin,
MathPlugin, Movable2DPlugin, and
NarrowPhase2DPlugin. Register these plugins before this one;
registering Gravity2DPlugin does not install them automatically.