The Corona iPhone simulator does not run at the same speed as an iPhone. Any programs built using frame-based animation run faster on the simulator than on an iPhone. This makes it impossible to use enterFrame on the simulator to properly sync events and music, even using time-based animation.
[code]
– This is a bare bones app designed to run at maximum FPS on both the phone and the simulator
– The FPS is calculated in two different ways
– Try with config.lua set to 60 fps
– Run on Simulator, and then run on device to see the difference
– In one minute, there are over 100 more enterFrame events on the simulator than the phone.
local FPSCounter = 0
local FPSCounterAlt = 0
local FPMCounter = 0
local totalDelta = 0
local tPrevious = system.getTimer()
local MSPFDisplay = display.newText( “?? ms per frame”, 0, 0, “Futura-Medium”, 36)
MSPFDisplay.xScale, MSPFDisplay.yScale = 0.5, 0.5
MSPFDisplay:setTextColor (127, 127, 127)
MSPFDisplay:setReferencePoint(display.CenterReferencePoint)
MSPFDisplay.x, MSPFDisplay.y = display.contentWidth * 0.5, display.contentHeight * 0.5 - 50
local FPSDisplay = display.newText( “?? frames per second”, 0, 0, “Futura-Medium”, 36)
FPSDisplay.xScale, FPSDisplay.yScale = 0.5, 0.5
FPSDisplay:setTextColor (127, 127, 127)
FPSDisplay:setReferencePoint(display.CenterReferencePoint)
FPSDisplay.x, FPSDisplay.y = display.contentWidth * 0.5, display.contentHeight * 0.5
local FPSDisplayAlt = display.newText( “?? frames per second”, 0, 0, “Futura-Medium”, 36)
FPSDisplayAlt.xScale, FPSDisplayAlt.yScale = 0.5, 0.5
FPSDisplayAlt:setTextColor (127, 127, 127)
FPSDisplayAlt:setReferencePoint(display.CenterReferencePoint)
FPSDisplayAlt.x, FPSDisplayAlt.y = display.contentWidth * 0.5, display.contentHeight * 0.5 + 50
local FPMDisplay = display.newText( “?? frames per minute”, 0, 0, “Futura-Medium”, 36)
FPMDisplay.xScale, FPMDisplay.yScale = 0.5, 0.5
FPMDisplay:setTextColor (127, 127, 127)
FPMDisplay:setReferencePoint(display.CenterReferencePoint)
FPMDisplay.x, FPMDisplay.y = display.contentWidth * 0.5, display.contentHeight * 0.5 + 100
local function gameLoop(e)
FPSCounter = FPSCounter + 1
FPSCounterAlt = FPSCounterAlt + 1
FPMCounter = FPMCounter + 1
local tDelta = e.time - tPrevious
tPrevious = e.time
MSPFDisplay.text = (tDelta … “ms per frame”)
MSPFDisplay:setReferencePoint(display.CenterReferencePoint)
MSPFDisplay.x, MSPFDisplay.y = display.contentWidth * 0.5, display.contentHeight * 0.5 - 50
totalDelta = totalDelta + tDelta
if FPSCounter == 60 then – Calculate FPS over past 60 frames
local totalSeconds = totalDelta * .001 – Number of seconds over past 60 frames
local FPS = 60 / totalSeconds – Get FPS
FPSDisplay.text = (FPS … " frames per second")
FPSDisplay:setReferencePoint(display.CenterReferencePoint)
FPSDisplay.x, FPSDisplay.y = display.contentWidth * 0.5, display.contentHeight * 0.5
totalDelta = 0
FPSCounter = 0
end
end
local function FPSCountAlt() – Print number of frames over last 60 seconds
FPSCounterAlt = FPSCounterAlt
FPSDisplayAlt.text = (FPSCounterAlt … " frames per second")
FPSDisplayAlt:setReferencePoint(display.CenterReferencePoint)
FPSDisplayAlt.x, FPSDisplayAlt.y = display.contentWidth * 0.5, display.contentHeight * 0.5 + 50
FPSCounterAlt = 0
end
local function FPMCount() – Print number of frames over last 1 minute
FPMDisplay.text = (FPMCounter … " frames per minute")
FPMDisplay:setReferencePoint(display.CenterReferencePoint)
FPMDisplay.x, FPMDisplay.y = display.contentWidth * 0.5, display.contentHeight * 0.5 + 100
FPMCounter = 0
end
timer.performWithDelay(1000, FPSCountAlt, 0) – Every Second
timer.performWithDelay(60000, FPMCount, 0) – Every Minute
Runtime:addEventListener(“enterFrame”, gameLoop ) – Every Frame
[/code] [import]uid: 14598 topic_id: 9820 reply_id: 309820[/import]