StaticframeNumber 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.
StaticframeNumber 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.
StaticrenderingThe 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.
StaticrestartRestarts 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.
StaticsetThe 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).
OptionalonDraw: (() => void)StaticsetThe 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).
OptionalonStarted: (() => void)StaticsetStaticstartThe method which starts the game.
You are supposed to set BeetPx.setOnStarted, BeetPx.setOnUpdate, and BeetPx.setOnDraw before this one.
StaticcanvasThe canvas size as set in BpxEngineConfig's canvasSize.
StaticgetGives 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.
StaticisStaticmuteMutes the audio globally.
The global mute/unmute logic is independent from BeetPx.mutePlayback and BeetPx.unmutePlayback.
Optionalopts: { OptionalfadeStaticmuteMutes a given playback, denoted by its BpxAudioPlaybackId.
Optionalopts: { OptionalfadeStaticpausePauses a given playback, denoted by its BpxAudioPlaybackId.
StaticresumeResumes a given paused playback, denoted by its BpxAudioPlaybackId.
StaticstartStart to play a given sound, once.
Optionalopts: { OptionalmuteOptionalonStaticstartStart to play a given sound, looped.
Optionalopts: { OptionalmuteOptionalonStaticstartStart to play a given sound, defined by a sequence of audio samples.
Optionalopts: { OptionalmuteOptionalonStaticstopCompletely stops a given playback, denoted by its BpxAudioPlaybackId.
Optionalopts: { OptionalfadeStaticunmuteUn-mutes the audio globally.
The global mute/unmute logic is independent from BeetPx.mutePlayback and BeetPx.unmutePlayback.
Optionalopts: { OptionalfadeStaticunmuteUn-mutes a given playback, denoted by its BpxAudioPlaybackId.
Optionalopts: { OptionalfadeStaticgetRetrieves 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
StaticgetRetrieves 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
StaticgetRetrieves 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
StaticdetectedThe type of a browser detected by the engine. It is tightly related to the gamepad mapping detection.
StaticgetStaticgetA 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.
StaticgetReturns a 2D vector where:
StaticgetTells 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.
StaticisTells whether any of the game buttons is pressed right now.
For a list of available game buttons check BpxGameButtonName
StaticisTells whether a given button is pressed right now.
StaticsetAllows 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.
StaticwasTells 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
StaticwasTells whether a given game button changed from released to pressed in the recent game loop iteration.
StaticwasTells whether a given game button changed from pressed to released in the recent game loop iteration.
StaticisWhether the game pause is active.
StaticpausePauses 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.
StaticresumeResumes 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.
StaticwasWhether the game pause was activated in the most recent game loop iteration. * *
StaticwasWhether the game pause was deactivated in the most recent game loop iteration. * *
StaticclearStaticloadAllows 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.
StaticsaveAllows 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.
StaticlogPrints 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[]StaticlogPrints 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[]StaticlogPrints 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[]StaticlogPrints 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[]StaticdebugLet'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