Because i was sick of FPS calculations cluttering draw, i came up with this:
FPS = class()
function FPS:init(typ,col,x,y,fs,auto)
FPS.col = col or FPS.col or 256
FPS.fontsize = fs or FPS.fontsize or 25
FPS.x,FPS.y=x or FPS.x or WIDTH-FPS.fontsize,y or FPS.y or HEIGHT-FPS.fontsize
FPS.auto = auto or FPS.auto or false
FPS:settype(typ or FPS.type or 2)
if FPS.col == 256 then
FPS.style = function()
fill(FPS.col);blendMode(ONE_MINUS_DST_COLOR,ONE_MINUS_SRC_COLOR);
textMode(CENTER);fontSize(FPS.fontsize);font("Futura-Medium")
end
else
FPS.style = function()
fill(FPS.col);textMode(CENTER);fontSize(FPS.fontsize);font("Futura-Medium")
end
end
if not FPS.active then
FPS.active = true
FPS.odraw = draw
if FPS.auto then
draw = function()
FPS.odraw()
pushStyle()
FPS.style()
text(FPS.calc(),WIDTH-FPS.fontsize+5,HEIGHT-FPS.fontsize+10)
popStyle()
end
else
draw = function()
FPS.odraw()
pushStyle()
FPS.style()
text(FPS.calc(),FPS.x,FPS.y)
popStyle()
end
end
end
end
function FPS:remove()
draw = FPS.odraw
FPS.active = nil
end
function FPS:settype(typ)
FPS.type = typ
FPS.calc = FPS.types[typ][1]
FPS.types[typ][2]()
end
FPS.types = {{
-- TYPE 1 --
function()
FPS.frame = FPS.frame + 1
FPS.etime = FPS.etime + DeltaTime
return math.floor(FPS.frame/FPS.etime+.5)
end,
function()
FPS.frame = 0
FPS.etime = 0
end },{
-- TYPE 2 --
function()
FPS.fps = .95*FPS.fps+.05*(1/DeltaTime)
return math.floor(FPS.fps+.5)
end,
function()
FPS.fps = 60
end },{
-- TYPE 3 --
function()
table.insert(FPS.deltable,1,DeltaTime)
FPS.etime = FPS.etime + DeltaTime - FPS.deltable[120]
table.remove(FPS.deltable,120)
return math.min(math.floor(119/FPS.etime+.5),60)
end,
function()
FPS.deltable = {}
for i=1,120 do
FPS.deltable[i] = 0
end
FPS.etime = 0
end }}
To use it simply call FPS() in setup and it will make the indicator in the top right corner. You can then remove the indicator with FPS:remove()
By default the color is the negative of whatever is behind it