I am using subdirectories to organize most of my files. I only keep main.lua and a few other files in the root of my project.
This is working well for me, except when I need to access image files from a lua file and that lua file is in a subdirectory.
See example below for clarification:
Path Layout:
aProject\
|
+---main.lua
|
+---images\
| |
| +---anImage.png
|
+---libs\
|
+---aLib.lua
Contents of aLib.lua
module(..., package.seeall)
local imgPath = "images/anImage.png"
function newImage()
local retImg = display.newImageRect( imgPath, 100, 100 ) -- THIS FAILS
return retImg
end
Code in main.lua:
local aLib = require("libs.aLib"
.
.
local imgPath = "images/anImage.png"
local imageRect1 = display.newImageRect( imgPath, 100, 100 ) -- THIS WORKS
local imageRect2 = aLib.newImage() -- THIS FAILS
Note: The call to aLib.newImage() works, but the internal call to newImageRect() fails.
My question is, “Is there some secret sauce for code in lua files, which are in subdirectories, to access images/sounds in other subdirectories?” I’d love to see a code example to this.
Note: I’ve been searching around the forums and have thus far not found a solution, but if a solution does exist please forgive my not (yet) finding it.
Cheers,
Ed [import]uid: 110228 topic_id: 25946 reply_id: 325946[/import]
[import]uid: 41884 topic_id: 25946 reply_id: 104998[/import]