Engine Utilities
Here you'll find some useful functions to operate the engine and your game using Cave.
Time Related
This is the Delta Time function. You can multiply this value by ano movement factor in your game in order to make sure that it will run at the same speed regardless of the FPS. Check this link to undertstand this concept a bit better. Reference:
cave.getDeltaTime() -> float
You can use this function to see at how many FPS your game is running at.
cave.getFPS() -> float
General
Use this function to Quit the game. It will close the game application. If you're editing the game and hit stop, it will just stop the game execution. Reference:
cave.quitGame()
In order to handle user events (such as keyboard and mouse inputs), you need to get the Cave's event system. Use this function for the matter. Reference:
# NOTE: See the documentation for **cave.Events** to get more details.
cave.getEvents() -> Events
Scene
In order to make your games, you'll need to be able to manipulate scenes. Here is you you handle them:
Returns the current scene being played by the engine:
cave.getCurrentScene() -> Scene
# Alias (same function, different name):
cave.getScene() -> Scene
Allows you to change scenes:
cave.setScene(name: str)
If you want to Restart the current scene, here is what you're looking for:
cave.restartCurrentScene()
Mouse
You can use those functions to get/set the mouse position. If you pass True to cave.getMousePosition
(normalize parameter), it will divide the mouse pos by the window size and returns the value to you, ranging from 0.0 and 1.0. Otherwise, the value will be in pixels. You can only set the mouse position in pixels. If you need to convert the normalized mouse pos back to pixels, consider multiplying it by the window size.
cave.getMousePosition(normalize=False) -> Vector2
cave.setMousePosition(x: int, y: int)
Window
cave.getWindowSize() -> Vector2
Audio Playing
NOTE: Check the Assets > Audio Playing
category for more details!
You can play any sound you want anytime by calling the cave.playSound
function. You'll need to pass the asset name for the sound (exactly how it is written in the asset browser) and the optional parameters:
Parameter | Description |
---|---|
volume | How loud or quiet the sound will be. 0 means muted, 1 means max. |
fadeIn | In seconds, if greated than zero, it will slowly fade in the sound by the amount of time you pass. |
loop | How many times you want the sound to be played. -1 means that it will play forever, zero means that it will play once and 1 (or more) means that it will play and repeat by 1 (or the number you pass). |
This function returns an AudioTrackInstance
that allows you to later change those values, pause/resume the sound and more. Reference code:
cave.playSound(name: str, volume=1.0, fadeIn=0.0, loop=0) -> AudioTrackInstance