RG Game library
Overview
RetroLib is a Lua library designed to facilitate the development of 2D games and applications in Retro Gadget. It provides functionality for graphics rendering, collision detection, easing animations, and various utility functions.
You can find a sample Gadget that uses the library in the tutorial section of the game.
Graphics
lib.CreateSprite( spritesheet SpriteSheet, spriteX, spriteY, position vec2, scale vec2, animationSpeed number, renderOrder number ) table
This function creates and return a sprite instance with the specified parameters and adds it to the rendering queue.
Sprites can be dynamically positioned, scaled, and animated.
Sprite variables:
spritesheetThe spritesheet containing the sprite image.spriteX,spriteYThe coordinates of the sprite image within the spritesheet.positionThe position of the sprite in 2D space.rotationThe angular rotation of the sprite in 2D space.scaleThe scaling factor of the sprite.colorThe base color of the sprite. By default is set to color.whitebgColorThe base color of the background of the sprite. By default is set to color.clearflipXStore the flip status of the sprite on the X axisflipYStore the flip status of the sprite on the Y axisframeCurrent frame of the current sprite animationanimationsTable of sprites coordinates animationanimationSpeedThe speed of animation playbackcurrentAnimationthe index of the currently playing animationcollidertable of the colliders added to the spriteactivedetermine if the sprite is rendered or not *renderOrderThe order in which the sprite is rendered relative to other sprites.
Sprite methods:
sprite:FlipSpriteX( flip boolean )
Flips the sprite horizontally if flip value is true. Flip value is stored in the sprite.
sprite:FlipSpriteY( flip boolean )
Flips the sprite vertically if flip value is true. Flip value is stored in the sprite.
sprite:RotateSprite( angle )
Rotates the sprite by the specified angle (in radians).
sprite:ScaleSprite( scale vec2 )
Scales the sprite by the specified scale vector.
sprite:MoveX( xValue )
Moves the sprite horizontally by the specified xValue.
sprite:MoveY( yValue )
Moves the sprite vertically by the specified yValue.
sprite:Move( position vec2 )
Moves the sprite to the specified position.
sprite:SetRenderOrder( value number )
Sets the rendering order of the sprite.
Starts the animation of the sprite.
Stops the animation of the sprite.
sprite:CreateAnimation( animations )
Creates an animation for the sprite.
sprite:SetAnimation( animation number )
Sets the current animation of the sprite.
Draws the animated sprite.
Draws the sprite without animation.
Collisions
CircleCollider:new( position vec2, radius number, tag string ) table
Creates and return a circle collider with the specified parameters.
CircleCollider variabiles:tagcan be used to check the colliderpositionthe position of the colliderradiusthe radius of the circle collidertypethe type of the collider
BoxCollider:new( position vec2, width number, height number, tag string ) table
Creates and return a box collider with the specified parameters.
BoxCollider variables:tagcan be used to check the colliderpositionthe position of the colliderwidththe width of the boxheightthe height of the boxcentrethe centre of the box based on its sizetypethe type of the collider
Easings
lib.EasingTypes = {
Linear
InQuad
OutQuad
InCubic
OutCubic
InQuart
OutQuart
InQuint
OutQuint
InSine
OutSine
InExpo
OutExpo
InCirc
OutCirc
InElastic
OutElastic
InBack
OutBack
InBounce
OutBounce
}
The easings need four parameters:
- t = time
- b = begin
- c = change (ending - beginning)
- d = duration
lib.EasingManager:new( ) table
Creates and return a new easing manager.
Creates a new easing instance.
easing:EaseNumber( startValue, endValue, duration, easingType, onEaseValue, onEaseComplete )
Applies an easing function to interpolate between values.
Updates active easings.
Utils
lib.moveTableElement( table, fromIndex, toIndex )
Moves an element within a table.
lib.findIndex( table, element )
Finds the index of an element in a table.
Debug
Debugging RetroLib provides a debug mode that can be toggled on or off. When enabled, debug messages are printed to the console and colliders are drawn providing useful information for troubleshooting and monitoring the library's behaviour.
To enable debug mode, set lib.debugMode to true:
lib.debugMode = true