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:
spritesheet
The spritesheet containing the sprite image.spriteX
,spriteY
The coordinates of the sprite image within the spritesheet.position
The position of the sprite in 2D space.rotation
The angular rotation of the sprite in 2D space.scale
The scaling factor of the sprite.color
The base color of the sprite. By default is set to color.whitebgColor
The base color of the background of the sprite. By default is set to color.clearflipX
Store the flip status of the sprite on the X axisflipY
Store the flip status of the sprite on the Y axisframe
Current frame of the current sprite animationanimations
Table of sprites coordinates animationanimationSpeed
The speed of animation playbackcurrentAnimation
the index of the currently playing animationcollider
table of the colliders added to the spriteactive
determine if the sprite is rendered or not *renderOrder
The 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:tag
can be used to check the colliderposition
the position of the colliderradius
the radius of the circle collidertype
the 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:tag
can be used to check the colliderposition
the position of the colliderwidth
the width of the boxheight
the height of the boxcentre
the centre of the box based on its sizetype
the 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