Scrappy Time

Scrappy Time is a simple time management library for Solar2D that simplifies time based movement.

As with all my plugins it is free to use however if you find it useful, and are able to, I’d appreciate a coffee.

Image Credit: Time free by ProSymbols from the Noun Project.

Getting Started

There are multiple ways to include the library in your project, the simplest is probably via the plugin, as outlined below, however if you wish you can also access the source code.

Plugin

build.settings


settings =
{
    plugins =
    {
        ["plugin.scrappyTime"] =
        {
            publisherId = "com.scrappyferret",
            supportedPlatforms =
            {
                iphone = { url="https://plugins.scrappyferret.com/scrappyTime/iphone.tgz" },
                android = { url="https://plugins.scrappyferret.com/scrappyTime/android.tgz" },
                macos = false,
                win32 = false
            },
        },
    },
}

main.lua


require( "plugin.scrappyTime" )

Scrappy.Time:init()

Source Code

If you wish you to access the source code directly it is available on GitLab here.

You can then clone or fork it if you wish, or add the library as a submodule to your project with this command:

git submodule add https://gitlab.com/scrappyferret-libs/scrappy-time.git time

However you get the source code into your project, you will then need to include it and initiate it.

main.lua


require( "time.core" )

Scrappy.Time:init()

API

Scrappy.Time:init()

Initiates the library.


Scrappy.Time:delta()

Gets the current time delta for the game.


Scrappy.Time:fps()

Gets the fps of the game.


Examples

Move a player object using time based velocity.

function onUpdate()
    player.x = player.x + ( velocity.x * Scrappy.Time:delta() )
    player.y = player.y + ( velocity.y * Scrappy.Time:delta() )
end

Display the current FPS in the console.

function onUpdate()
   print( "FPS: ", Scrappy.Time:fps() )
end