Hi all,
Is there some kind of function/method that I might use to check if a file or process is “loaded” before proceeding? Basically I have a sizeable function that runs on the level start, which (in addition to several other things) processes a text file in the documents directory. This file contains all of the data for the particular level, so obviously it needs to load completely before the level can actually begin.
What I have been doing is just setting a timer of around 2 seconds before the level starts, which (in most tests) allows the file to be processed before the level starts. However, if I reduce the length of that timer, on slower devices (i.e. Touch 3rd-gen) the file doesn’t fully load and thus the game breaks. On faster devices it loads properly, but this might depend on the size of the text file being processed!
So my basic question is: can I determine WHEN the file is fully loaded? And have it not dependent on the speed of the device or the processing time for the file? I don’t mind using a timer, but if the file processes in 0.3 seconds on the iPad2, I’d prefer the game to start immediately, not after 2 seconds.
One idea I had was checking if an image (i.e. the background image for the level) “exists” during a Runtime listener, as in:
local function startLevel()
if ( levelInfo.backImg ) then
Runtime:removeEventListener( "enterFrame", startLevel )
-- START LEVEL!
end
end
local function prepStart()
Runtime:addEventListener( "enterFrame", startLevel )
end
Any better ideas or suggestions? I’m guessing that other developers have dealt with this kind of thing before, i.e. needing to read/process an external file before something else can happen…
Thanks,
Brent
[import]uid: 9747 topic_id: 8316 reply_id: 308316[/import]