local sStartUpdateTime, sFrameRate, sUpdateMessageId # start the game loop when stack opens on preOpenStack set the acceleratedRendering of this stack to true startUpdatingTheScreen 50 end preOpenStack # set the game loop in action on startUpdatingTheScreen pFrameRate put pFrameRate into sFrameRate put 0 into sStartUpdateTime send "sendUpdateScreenMessage" to me in 0 millisecs put the result into sUpdateMessageId end startUpdatingTheScreen # cancel the game loop on stopUpdatingTheScreen if sUpdateMessageId is not empty then cancel sUpdateMessageId end if put empty into sUpdateMessageId end stopUpdatingTheScreen # this handler is the "game loop" itself on sendUpdateScreenMessage put the long seconds into tThisFrameTime if sStartUpdateTime is 0 then put the long seconds into sStartUpdateTime end if lock screen send "updateScreen" to this card unlock screen put the long seconds into tTheTimeNow put round((tTheTimeNow - sStartUpdateTime) * sFrameRate + 0.5) into tNextFrameCount send "sendUpdateScreenMessage" to me in (sStartUpdateTime + (tNextFrameCount * (1 / sFrameRate)) - tTheTimeNow) seconds put the result into sUpdateMessageId end sendUpdateScreenMessage