Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Frames per second — Gideros Forum

Frames per second

seppseppseppsepp Member
edited March 2013 in General questions
Hi @all,

is there a simple way to get the current frames per seconds count? I guess, Application:getFps() is something _different_, right?

Thanks in advance!

Sebastian
Tagged:

Comments

  • techdojotechdojo Guru
    Accepted Answer
    The simple way is to just use an enterFrame listener that keeps a check on the current time and then displays an average every 60 (or 30) frames. I have some code somewhere (and it's also available on here if you search) that will do that for you - although I suspect someone will post some code before I get chance to... :)
    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
  • Ok, thanks for the hint. Thats exactly what I do now. On "enterFrame" a counter gets increased. When this counter is higher then Application:getFps() I do measure times using os.timer() and do some math et voila - fps. (Btw: It's around 60 while rendering about 2000 sprites =) .)
  • Deployed on the iPad it actually says 104 fps :D .
  • techdojotechdojo Guru
    Accepted Answer
    Here's the code I use
    -- -------------------------------------------------------------------------
    -- local methods required to put an FPS counter on the screen...
     
     
    local frame = 0
    local timer = os.timer()
    local qFloor = math.floor
    local fps, scount	
     
    local function updateFPS(e)
     
    	frame = frame + 1
    	if frame == 60 then
     
    		local currentTimer = os.timer()
    		fps:setText(""..qFloor(60 / (currentTimer - timer)))
     
    		local width = fps:getWidth()
    		fps:setPosition(WIDTH-(width+10), 28)	--HEIGHT-10)
    		frame = 0; timer = currentTimer	
    	end
    end
     
    -- -------------------------------------------------------------------------
     
    initFPS = function(group)
     
    	fps = TextField.new(nil,"  ")
    	fps:setTextColor(0x00FFFF)
    	fps:setScale(2,2)
    	fps:addEventListener(Event.ENTER_FRAME,updateFPS)
    	group:addChild(fps)
     
    end
     
    initFPS(stage)	-- Add a quick FPS counter on the screen (REMOVE for final build)
    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
  • Thanks. I did it a bit different - packed it into a Gideros class. But I did it basically the same way.
  • enterFrame event will give you e.deltaTime so you just need fps=1/e.deltaTime or you can average 10-30 samples if you want
Sign In or Register to comment.