i'm making preloader large application. today error occurred "no such file or directory". error occurs on android device. on computer(in simulator) works fine. file names , directories lowercase.
code:
--------------------------------------------- ---------------- Прелоадер ------------------ -- Сервис по загрузке текстур, звука -------- --------------------------------------------- textures = {} -- место в оперативной памяти для текстур sounds = {} -- место в оперативной памяти для звука local preloader = {} local path = { animations = "assets/images/animations/", army_run = "assets/images/animations/army_run/", area = "assets/images/area/", access = "assets/images/area/access/", artefacts = "assets/images/artefacts/", castles = "assets/images/building/castles/", mining = "assets/images/building/mining/", flags = "assets/images/flags/", interface = "assets/images/interface/", marker = "assets/images/interface/marker/", items = "assets/images/items/", raw = "assets/images/raw/", } -- Место для путей к текстурам preloader.texture = {} -- Место для путей к звуку preloader.sound = {} -- Загрузка текстур в оперативную память preloader.loadingtextures = function(arr) textures[arr.id] = {} = 1, #arr local name = string.gsub(arr[i], '.*(.*)/', '') textures[arr.id][name] = graphics.newtexture( { type="image", filename = arr[i] } ) textures[arr.id][name]:preload() end end -- Загрузка звука в оперативную память preloader.loadingsounds = function() = 1, #preloader.sound sounds[preloader.sound[i]] = audio.loadsound( "snd/"..preloader.sound[i] ) end end -- Таймер preloader.gettimer = function() return system.gettimer() end -- Окно загрузки preloader.screenloader = nil preloader.loadershow = function() if(preloader.screenloader)then return false end preloader.screenloader = display.newgroup() preloader.screenloader.x = _w/2 preloader.screenloader.y = _h/2 local screen = display.newrect( 0, 0, _w, _h ) screen:setfillcolor( 0, 0, 0 ) preloader.screenloader:insert(screen) local imgload = "assets/images/animations/army_run/150.png" local sheetload = graphics.newimagesheet( imgload, { width = 224, height = 224, numframes = 8 } ) local animload = display.newsprite( preloader.screenloader, sheetload, { start = 1, count = 8, time = 800, loopcount=0 } ) animload.xscale, animload.yscale = _h*.001, _h*.001 animload.x, animload.y = 0, _h*-.07 animload:play() -- Загрузка в процентах tfloader = display.newtext( texts.preloader.loading..": 0%", 0, _h*.08, font, _h*.035 ) tfloader:settextcolor( 1,1,1) preloader.screenloader:insert(tfloader) preloader.screenloader.tf = tfloader -- Загрузка в этапах steploader = display.newtext( texts.preloader.start_load, 0, _h*.125, font, _h*.022 ) steploader:settextcolor( 160/255, 160/255, 160/255 ) preloader.screenloader:insert(steploader) preloader.screenloader.step = steploader end -- Создание массивов с путями preloader.createpath = function() k, v in pairs(path) local = 0 preloader.texture[k] = { id = k } l in lfs.dir(v) if ( l ~= "." , l ~= ".." , l ~= "..." ) = + 1 preloader.texture[k][i] = v..l end end end end -- Запуск прелоадера и контроль процесса загрузки preloader.start = function() -- Создаём шаги для загрузки local loading_steps = {} -- Шаг 1 - Загрузка путей table.insert(loading_steps, function() preloader.createpath() preloader.screenloader.step.text = texts.preloader.path_load..'...' end) -- Шаг 2 - Загрузка текстур интерфейса table.insert(loading_steps, function() preloader.loadingtextures(preloader.texture.interface) preloader.loadingtextures(preloader.texture.marker) preloader.screenloader.step.text = texts.preloader.interface_load..'...' end) -- Шаг 3 - Загрузка анимаций table.insert(loading_steps, function() preloader.loadingtextures(preloader.texture.animations) preloader.loadingtextures(preloader.texture.army_run) preloader.screenloader.step.text = texts.preloader.animations_load..'...' end) -- Шаг 4 - Создание карты table.insert(loading_steps, function() preloader.loadingtextures(preloader.texture.area) preloader.loadingtextures(preloader.texture.access) preloader.loadingtextures(preloader.texture.castles) preloader.loadingtextures(preloader.texture.mining) preloader.screenloader.step.text = texts.preloader.map_load..'...' end) -- Шаг 5 - Загрузка ресурсов table.insert(loading_steps, function() preloader.loadingtextures(preloader.texture.raw) preloader.loadingtextures(preloader.texture.items) preloader.loadingtextures(preloader.texture.artefacts) preloader.screenloader.step.text = texts.preloader.res_load..'...' end) -- Шаг 6 - Загрузка параметров игрока table.insert(loading_steps, function() preloader.loadingtextures(preloader.texture.flags) preloader.screenloader.step.text = texts.preloader.res_load..'...' end) local loading_steps_max = #loading_steps+1 local st = preloader.gettimer() preloader.loadershow() local function mainhandler(e) if(#loading_steps>0)then loading_steps[1]() table.remove(loading_steps, 1) if(preloader.screenloader)then local loading_p = math.floor((loading_steps_max - #loading_steps)*100/loading_steps_max) preloader.screenloader.tf.text = texts.preloader.loading..': '..loading_p..'%' end return true end preloader.loaderclose() print('time load: '..(preloader.gettimer()-st)..'ms') runtime:removeeventlistener("enterframe", mainhandler) end runtime:addeventlistener("enterframe", mainhandler) end -- Окончание загрузки preloader.loaderclose = function() if(preloader.screenloader)then if(preloader.screenloader.removeself)then preloader.screenloader:removeself() end end preloader.screenloader = nil -- Переход на стартовую сцену composer.gotoscene( start_scene, "fade", 0 ) end -- Сборщик мусора preloader.garbage_collector = function() key in pairs(textures) i=1, #textures[key] textures[key][i]:releaseself() end end textures = {} end return preloader
that's how show images on stage:
m.dial = display.newimagerect( m.gr, textures.interface["btn_compas_comp.png"].filename, textures.interface["btn_compas_comp.png"].basedir, 272, 272 ) m.dial.x, m.dial.y = x, y
thanks in advance friends.
1) all file names , directories lowercase
- suggest double-check because android filesystem case sensitive.
2) check build.settings
ensure excludefiles
section doesn't include of directories code
edit: idea based on corona lfs doc - try following before loading:
local resourcespath = system.pathforfile( "", system.resourcedirectory ) -- change current working directory local success = lfs.chdir( resourcespath ) --returns true on success
i guess lfs doesn't point on resource directory default. assets should in directory, don't try modify them - for security reasons, directory read-only , enforced operating system, not corona.
edit 2: solution don't rely on current directory
preloader.createpath = function() k, v in pairs(path) local = 0 local pathfordirectory = system.pathforfile(v, system.resourcedirectory) preloader.texture[k] = { id = k } l in lfs.dir(pathfordirectory) if ( l ~= "." , l ~= ".." , l ~= "..." ) = + 1 preloader.texture[k][i] = v..l end end end end
Comments
Post a Comment