-- --------------------------------------------------------------- local methods required to put an FPS counter on the screen...local frame =0local timer =os.timer()local qFloor =math.floorlocal fps
-- Global table for OSD
DEBUG ={"","","","","","","","","","","","", }local DEBUG_TXT ={}function DEBUG_RESET()for i=1,#DEBUG do DEBUG[i]=""endend-- -------------------------------------------------------------localfunction updateFPS(e)
frame = frame + 1if frame ==60thenlocal currentTimer =os.timer()
fps:setText(""..qFloor(60/(currentTimer - timer)))local width = fps:getWidth()
fps:setPosition(320-(width+10), 28)
frame =0; timer = currentTimer
endfor i=1,#DEBUG_TXT do
DEBUG_TXT[i]:setText(DEBUG[i])endend-- ------------------------------------------------
initFPS =function(group)
fps = TextField.new(nil," ")
fps:setTextColor(0x00FFFF)
fps:setScale(2,2)
fps:addEventListener(Event.ENTER_FRAME,updateFPS)
group:addChild(fps)local y =20for i=1,#DEBUG dolocal d = TextField.new(nil,DEBUG[i])
d:setTextColor(0x00FFFF)
d:setScale(2,2)
d:setPosition(4,y); y = y + 18
group:addChild(d)
DEBUG_TXT[i]= d
endend
initFPS(stage)-- Add a quick FPS counter on the screen (REMOVE for final build)
Just add the above to the end of main.lua file and you should be good to go. Also I added an extra bit - I declare a simple global table called DEBUG all with empty strings.
What this means is that you can then set any element of the DEBUG array to any value (or string) and it'll be displayed on the screen.
ie.
DEBUG[1] = count DEBUG[2] = someString
etc
Any changes will get instantly updated on screen - it's useful to be able to put a "watch" on a particular value without having loads of print statements cluttering up the output log.
You can call the DEBUG_RESET() function to clear all of the entries.
Hope this helps.
Jon...
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
@Tom2012, I use my BhDebugInfo class to display a simple debugging HUD that includes device info, fps and used memory. You can get it on GitHub. You just need to include the Lua file (and its font) in your project for it to work. You can turn if off by choosing "Exclude from execution" in the Gideros IDE.
local frame = 0 local timer = os.timer() local function displayFps() frame = frame + 1 if frame == 60 then local currentTimer = os.timer() print(60 / (currentTimer - timer)) frame = 0 timer = currentTimer end end
Comments
Also I added an extra bit - I declare a simple global table called DEBUG all with empty strings.
What this means is that you can then set any element of the DEBUG array to any value (or string) and it'll be displayed on the screen.
ie.
DEBUG[1] = count
DEBUG[2] = someString
etc
Any changes will get instantly updated on screen - it's useful to be able to put a "watch" on a particular value without having loads of print statements cluttering up the output log.
You can call the DEBUG_RESET() function to clear all of the entries.
Hope this helps.
Jon...
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I used site:giderosmobile.com/forum fps in google search
best regards
I found the best solution for me was:
local frame = 0
local timer = os.timer()
local function displayFps()
frame = frame + 1
if frame == 60 then
local currentTimer = os.timer()
print(60 / (currentTimer - timer))
frame = 0
timer = currentTimer
end
end
stage:addEventListener(Event.ENTER_FRAME, displayFps)