Static
frameNumber of frames processed since game started. It gets reset to 0 when BeetPx.restart is called. It counts update calls, not draw calls.
Usually you would use e.g. $timer instead of this low-level API.
Static
frameNumber of frames processed since game started, excluding the frames which happened during an active game pause. It gets reset to 0 when BeetPx.restart is called. It counts update calls, not draw calls.
Usually you would use e.g. $timer instead of this low-level API.
Static
renderingThe effective FPS (frames per second) of render calls. This does not count the update calls.
This value is used (with some averaging, to avoid quickly changing number) in the FPS display,
which is active in debug mode if BpxEngineConfig's
debugMode.fpsDisplay.enabled
is set to true
.
Static
restartRestarts the entire game.
It is important to properly set the game initialization logic through the BeetPx.setOnStarted,
so the $.restart()
will result with a properly restarted game.
An example usage would be to implement a game pause menu, with the "restart the game" as one of available options.
Static
setThe method to set a draw callback which is called every time the browser has a chance to repaint the canvas (requestAnimationFrame is used under the hood).
The draw callback is one of 2 recommended places to use BeetPxDraw
methods within
(the other one is the on-started callback set by BeetPx.setOnStarted).
Optional
onDraw: (() => void)Static
setThe method to set an on-started callback which is called every time the game is (re-)started.
While the game starts only once, it can be restarted many time with use of BeetPx.restart. In such case, the callback is useful for clearing up the game state, so nothing from the previous gameplay remains.
The timers, animations, and music restart on their own, there is no manual action needed.
The on-started callback is one of 2 recommended places to use BeetPxDraw
methods within
(the other one is the draw callback set by BeetPx.setOnDraw).
Optional
onStarted: (() => void)Static
setStatic
startThe method which starts the game.
You are supposed to set BeetPx.setOnStarted, BeetPx.setOnUpdate, and BeetPx.setOnDraw before this one.
Static
canvasThe canvas size as set in BpxEngineConfig's canvasSize
.
Static
getGives access to the main global AudioContext.
Typically, you wouldn't have to access to method on your own. But it might prove useful to have it in some unexpected scenario.
Static
isStatic
muteMutes the audio globally.
The global mute/unmute logic is independent from BeetPx.mutePlayback and BeetPx.unmutePlayback.
Optional
opts: { Optional
fadeStatic
muteMutes a given playback, denoted by its BpxAudioPlaybackId.
Optional
opts: { Optional
fadeStatic
pausePauses a given playback, denoted by its BpxAudioPlaybackId.
Static
resumeResumes a given paused playback, denoted by its BpxAudioPlaybackId.
Static
startStart to play a given sound, once.
Optional
opts: { Optional
muteOptional
onStatic
startStart to play a given sound, looped.
Optional
opts: { Optional
muteOptional
onStatic
startStart to play a given sound, defined by a sequence of audio samples.
Optional
opts: { Optional
muteOptional
onStatic
stopCompletely stops a given playback, denoted by its BpxAudioPlaybackId.
Optional
opts: { Optional
fadeStatic
unmuteUn-mutes the audio globally.
The global mute/unmute logic is independent from BeetPx.mutePlayback and BeetPx.unmutePlayback.
Optional
opts: { Optional
fadeStatic
unmuteUn-mutes a given playback, denoted by its BpxAudioPlaybackId.
Optional
opts: { Optional
fadeStatic
getRetrieves a previously fetched image.
Usually, you wouldn't need to directly call this method, as the image retrieval happens under the hood for operations like sprite drawing.
BpxEngineConfig'a assets
Static
getRetrieves a previously fetched JSON.
Right now there is no API which would make use of the fetched JSON under the hood.
Example use case for this method is when you develop your game level in LDtk and want to read the level's file in the game code.
BpxEngineConfig'a assets
Static
getRetrieves a previously fetched sound.
Usually, you wouldn't need to directly call this method, as the sound retrieval happens under the hood for operations like music playing.
BpxEngineConfig'a assets
Static
detectedThe type of a browser detected by the engine. It is tightly related to the gamepad mapping detection.
Static
getStatic
getA set of game input events captures since the last game loop iteration.
Typically you wouldn't need to use those this method unless dealing with custom even handling.
Static
getReturns a 2D vector where:
Static
getTells what input methods were used in the last game loop iteration.
Might be used to render in-game indications what button to press, with their sprites chosen based on which input method was recently used.
Static
isTells whether any of the game buttons is pressed right now.
For a list of available game buttons check BpxGameButtonName
Static
isTells whether a given button is pressed right now.
Static
setAllows to enable repeating for a given button.
Repeating means if the user presses the button for a longer timer,
the "just pressed" state is detected first after firstRepeatFrames
frames, then repetitively after loopedRepeatFrames
frames.
Static
wasTells whether any of the game buttons changed from released to pressed in the recent game loop iteration.
For a list of available game buttons check BpxGameButtonName
Static
wasTells whether a given game button changed from released to pressed in the recent game loop iteration.
Static
wasTells whether a given game button changed from pressed to released in the recent game loop iteration.
Static
isWhether the game pause is active.
Static
pausePauses the game. This works only if BpxEngineConfig.gamePause's available
is set to true
.
The game pauses is by default toggled with the "menu" button, but this method allows you to add other ways of activating the pause.
Static
resumeResumes the game. This works only if BpxEngineConfig.gamePause's available
is set to true
.
The game pauses is by default toggled with the "menu" button, but this method allows you to add other ways of deactivating the pause.
Static
wasWhether the game pause was activated in the most recent game loop iteration. * *
Static
wasWhether the game pause was deactivated in the most recent game loop iteration. * *
Static
clearStatic
loadAllows to bring back the previously persisted data.
The stored data is kept in the localStorage. It means it will be there as long as you the same web browser (with the same user profile active) on the same machine, without clearing the website's data.
Static
saveAllows to persist some data between separate game runs.
The stored data is kept in the localStorage. It means it will be there as long as you the same web browser (with the same user profile active) on the same machine, without clearing the website's data.
Static
logPrints to the console on the debug level, with use of console.debug
.
This one is run only in the debug mode.
You can implement BpxPrintDebug on a given object if you want it to be printed out in a custom way.
Rest
...args: unknown[]Static
logPrints to the console on the error level, with use of console.error
.
You can implement BpxPrintDebug on a given object if you want it to be printed out in a custom way.
Rest
...args: unknown[]Static
logPrints to the console on the info level, with use of console.info
.
You can implement BpxPrintDebug on a given object if you want it to be printed out in a custom way.
Rest
...args: unknown[]Static
logPrints to the console on the warn level, with use of console.warn
.
You can implement BpxPrintDebug on a given object if you want it to be printed out in a custom way.
Rest
...args: unknown[]Static
debugLet's you know whether the debug mode is on or off. To be used in combination with:
debugMode.available
set to true
;
key used to toggle the debug mode on/off
One of 3 main API entry points. This one provides you with the most of the BeetPx capabilities, except drawing.
Example