Web
To render a game for the browser use the @replay/web
package.
renderCanvas(game, options)
#
Render the game to a canvas. Can return an error if WebGL features are not supported.
#
Parametersgame
: Your Top-Level Game Sprite called with its props passed in, e.g.Game(gameProps)
.options
: (Optional) An object with the following properties:dimensions
: (Optional) A string that is either:"game-coords"
: (default) Use the game coordinates as pixels in the browser."scale-up"
: Scales the game so that it fills up the browser window.
nativeSpriteMap
: (Optional) A map of Native Sprite names and their web implementation.canvas
: (Optional) A canvas element to render to. If omitted, Replay will create a canvas in the document.windowSize
: (Optional) An object with width and height fields. Use to override the view size, instead of using the window size.imageResolution
: (Optional) Resolution of images provided in assets. E.g. for a DPI of 3 a 30 game coordinate image would be 90 x 90px. Default3
.maxPixels
: (Optional) Adjust default resolution game is rendered at (to reduce # pixels drawn in shaders).
mapInputCoordinates(getLocalCoords, inputs)
#
This can be used by Replay Test, see the docs there for more info.
#
InputsThe device.inputs
parameter of Sprite methods is of type:
The keys of KeysPressed
are based on the key
value of browser keyboard events. See keycode.info for values of event.key
.
justPressed
is only true
for one frame after an input is pressed, justReleased
for one frame after an input is released.