How to show fps in Solar 2d?

How to find out fps in Solar 2d? I want to make a frame rendering display.

Found this on https://code.solar2d.com/

1 Like
local vars = {}

local prevFrameTime = 0

vars.frame = {dt = 0, dts = 0, fps = 0, current = 0} --holds all data related to current frame, dt = delta time

local current, dt, dts, fps --recycled
local function onFrame(event)
    current = event.time
    dt = event.time - prevFrameTime --set delta time
    dts = dt / 1000 --set delta time in seconds
    fps = 1000 / dt
    --set to module
    vars.frame.dt = dt
    vars.frame.dts = dts
    vars.frame.fps = fps
    vars.frame.current = current
    prevFrameTime = current --store current frame time to be accessed on next frame
end

vars.screen = {width = display.contentWidth, height = display.contentHeight, halfWidth = display.contentWidth/2, halfHeight = display.contentHeight/2}

Runtime:addEventListener( "enterFrame", onFrame )

return vars

Not super performance but gives an idea

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.