Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codea Project Gist Created with AutoGist
--FPS = class(juice.text)
FPS = class()
function FPS:init()
--juice.text.init(self, "FPS", 0,0)
self.pos = vec2(0,0)
self.fps = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
self.idx = 0
end
function FPS:average()
local v = 0
for i = 1,#self.fps do
v = v + self.fps[i]
end
v = (v/(#self.fps))
self.string = string.format("FPS: %.1f",1/v)
end
function FPS:update(dt)
self.fps[self.idx + 1] = dt
self.idx = (self.idx + 1)%(#self.fps)
self:average()
end
function FPS:draw()
pushStyle()
fontSize(22)
fill(255)
text( self.string, self.pos.x, self.pos.y )
popStyle()
end
-- BatchTest
-- Use this function to perform your initial setup
function setup()
fps = FPS()
parameter.boolean("Batch", false, function(v)
print("Batching = "..tostring(v))
spriteBatching(v)
end)
parameter.boolean("UseMesh", false)
parameter.boolean("UseString", true)
img = readImage("Planet Cute:Character Horn Girl")
str = "Planet Cute:Character Horn Girl"
amt = 40
sw,sh = spriteSize("Planet Cute:Character Horn Girl")
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
smooth()
-- Do your drawing here
if UseMesh then
local m = mesh()
m.texture = "Planet Cute:Character Horn Girl"
for y = 1, amt do
for x = 1, amt do
m:addRect((x * 100)/(amt/10), (y * 140)/(amt/10), sw, sh)
end
end
m:draw()
else
for y = 1, amt do
for x = 1, amt do
if UseString then
sprite(str, (x * 100)/(amt/10), (y * 140)/(amt/10))
else
sprite(img, (x * 100)/(amt/10), (y * 140)/(amt/10))
end
end
end
end
fps.pos = vec2(WIDTH - 60, 20)
fps:update(DeltaTime)
fps:draw()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.