|
MochiEngine
|
This sections show a list with the classes and methods available to be used from a LUA script, being some of them C++ bindings and other of them defined directly in LUA and loaded at the engine setup.
MochiEngine already includes several lua libraries:
OS and I/O libraries have not been included purposedly. The engine is meant to allow easy modding, and adding those libraries could bring security issues with untrusted modders.
These LUA events are an implementation of an event buss pattern with a single channel. You are able to create and retrieve events, add listeners to them and fire them with an arbitrary set of parameters.
Retrieves (and creates if it doesn't exist) an event.
Adds a listener to the event. Put any amount of params needed. The "Fire" method will be have to be called with those parameters too if you want to retrieve the correct data.
Fires an event, triggering all listeners with the sent data.
Example:
Example:
NOTE: MochiEngine automatically includes the lua math library, so we have some other methods there. However, the math bindings could be improved with other methods like min and max. TODO.
WE have the coroutines library already included as part of the MochiEngine setup, but we have several utility functions that allow us to work easily with game development concepts, like tweens.
UpdateCoroutines is automatically called from Mochi::Scripting::ScriptingManager. It updates this frame for all active coroutines and deactivate Coroutines as needed.
Example:
Starts and stores a function as a coroutine. This function will be called each frame, stopping on Yield(), Wait(s) and WaitFor(predicate) until it finishes.
Inside a coroutine, it waits until the next frame.
Waits a defined amount of seconds with an internal timer and doing Yield() each frame until it gets to the specified time.
Example:
Waits until a predicate returns true. Until then, it returns Yield() each frame.
update_callback --> function(t, dt) end_callback --> function() time --> seconds
Tween is a function that creates a coroutine, updates each frame calling update_callback with the current t value (between 0 and 1) and the frame delta time and calling end_callback when it finishes, after the specified time (update_callback is called too at the last frame with t = 1). Example:
Considering that we have a reference to a sprite called "someSprite", this example moves the sprite from 0 to 20 in the x axis in an interval of 5 seconds, and then deletes it.
There is a list of binded methods that are not part of a class. That means that those methods can be called without creating instances of any class.
Different kind of logs to debug or get info from inside lua, making use of the engine logs.
These methods allow to create and destroy different kind of graphics that will be owned by Mochi::Scripting::ScriptingLayer.
resourcePath --> String. Path to the sprite in the catalog.
returns: Mochi::Graphics::SpriteBase
resourcePath --> String. Path to the animation data in the catalog.
startingFrame --> int. Frame index.
returns: Mochi::Graphics::Spritesheet
resourcePath --> String. Path to the animation data in the catalog.
mainAnimation --> int. Animation index.
returns: Mochi::Graphics::AnimatedSprite
resourcePath --> String. Path to the animation data in the catalog.
mainAnimation --> int. Animation index.
returns: Mochi::Graphics::OneshotAnimation
deletableElement --> Mochi::Graphics::SpriteBase or child class.
Same as the documented methods in Mochi::Input::IActionManager.
Returns --> bool
Returns --> float
Returns --> Mochi::Vector2f
returns --> float with delta time
returns --> float with delta time as it was unscaled
returns --> float. Scaled time span since application started until now
returns --> float. Real time span since application started until now
returns --> int. Operative system time as a timestamp since epoch. "Re-implemented" because we don't integrate the OS lua library.
Same as documented in Mochi::Audio::IAudioManager or its current implementation.
Some of the bindings are classes with its own state and binded methods.
Note that all methods available to a type of sprite is available too for each sprite type inheriting from it and its parents.
All methods accept the same parameters and return the same types as in the original classes.
Mochi::Graphics::AnimatedSprite
Mochi::Graphics::OneshotAnimation