Modify Frame Rate From Within Code? (SOLVED)

Hi,

Our “Flappy Bird” inspired top-down racing game will have 3 levels of difficulty.
We wish to modify the frame rate to accomplish the above.

How can we modify the frame rate from within code?
Let us know, thanks!

Jesse

I think this is what you’re looking for. Correct me if I’m wrong.

https://www.defold.com/ref/sys/#set_update_frequency:frequency

That works, but it’s not precise?
Locking to 30 FPS for “Child Mode” has 34 FPS?

How are you counting FPS?

-- Put functions in this file to use them in several other scripts.
-- To get access to the functions, you need to put:
-- require "my_directory.my_file"
-- in any script using the functions.

local M = {}

function M.UpdateFPSandMouseXY()
	FPS_FrameCount = (FPS_FrameCount + 1)
	local currentTime = socket.gettime()
	if ( currentTime > (FPS_LastSecond + 1) ) then
		FPS_TenSeconds[FPS_CurrentSecond] = FPS_FrameCount
		if (FPS_CurrentSecond < 10) then
			FPS_CurrentSecond = (FPS_CurrentSecond + 1)
		else
			FPS_CurrentSecond = 0
		end

		for index = 0, 10 do
			FPS_Average = (FPS_Average + FPS_TenSeconds[index])
		end

		FPS_Average = (FPS_Average / 11)
		FPS_Average = math.floor(FPS_Average)

		FPS_LastSecond = socket.gettime()
		FPS_FrameCount = 0
	end

	if (SecretCode[0] == 1 and SecretCode[1] == 0 and SecretCode[2] == 1 and SecretCode[3] == 0) then
		label.set_text(   "#MouseXY", "FPS=" .. tostring(FPS_Average) .. " [" .. tostring(  math.floor( mX * (360/WindowWidthTrue) )  ) .. "," .. tostring(  math.floor( mY * (640/WindowHeightTrue) )  ) .. "]"   )	
	end
end

return M

fps.lua (535 Bytes)

Try this instead, it uses builtin dt to calculate FPS.

2 Likes

Works!
Thanks!

Had to add a zero to one of the computations, was getting 599 as a value when it should be 59