Images Subdirectory Not Functioning...

The code is simple:

local function createScreen()
    local background= display.newImage(“images/background.png” , 10, 200)
end

But it just will not find images in a sub-directory. I cannot, for the life of me, figure out why. If I place in it in th same directory as main.lua, it works fine, but it will not look in sub-directories. And yes, I have double-checked, and they are corerctly named.

I first encountered this problem running through the Angry Birds in 30 minutes demo, when I had to dump all the gdk image files into the main folder, and I haven’t been able to do it since. I’m using Outlaw Version 3.0.14 (19) as my editor.

I know I can just dump images in the main folder to get around this probglem, but I need to know why it is malfunctioning…

I don’t know why it doesn’t work for you.  I wonder if “images” is a reserved name.  My sub-directory folder for all my png images is named “PNG”, and it never fails to load a file from that sub-directory.

Naomi

Tried renaming it to gdk, still doesn’t work. It just doesn’t want to recognize sub-directories.

Hi @jabberwock3,

Since there doesn’t appear to be anything wrong with your code, this might be an issue with Outlaw, or it might be an issue with the actual folder. Is it locked or restricted somehow?

Brent

This seems to work (for now):

local function createScreen()
    local background= display.newImage(“background.png”, images, 0, 0)
end

But it doesn’t work in this instance:

local circle=display.newImage(“exorcist.png”, gfx)

And to top it off, the image in the first example (despite my using the ‘Ultimate Config’ file) is stretching scaling up outside of the 1280x720 bounds of the screen without any further code. I’m flippin confused.

As for folders, they don’t appear to be locked, but with Win8, there’s probably some supersecret admin handshake I have to use to make sure. Seriously, everything defaults to ‘you can’t touch this…’

Hi @jabberwock3,

In the second example, what is “gfx”? Since you’re not specifying a parent display group… the optional first argument to newImage()… the second and third arguments (also optional) should be the left and top positions. Actually, same thing in the first example… “images” is what exactly? A display group?

Take a look at the API documentation here:

http://docs.coronalabs.com/api/library/display/newImage.html

Best regards,

Brent

I saw that and I was taking this…

display.newImage( filename [,baseDirectory] [, left, top] )

…as a possible example. I thought base directory referred to the folder I was keeping the images in (gfx is also an images folder, but for the Angry Birds in 30 minutes demo). It’s moot anyway, that previous functional code stopped working when I rebooted Outlaw.

So I’m still stuck withe question of why an image folder inside the same folder as the main.lua file, to whit:

Folder: Turn_Tracker

            main.lua

            config.lua

            build.settings

            Folder:images

                       background.png          

cannot be accessed through the use of…

    local background= display.newImage(“images/background.png”)
 

Am I mistaken in understanding that this means ‘look in the images folder inside the project folder and pull the background.png image from there’? Am I missing something? Every example I’ve seen online uses this same code to call images, but I’m having to dump all mine in the main folder for Corona to find them.

And I also can’t figure out why my 1280x720 image won’t fit my 1280x720 screen setting and is being blown up to a ridiculous size.

EDIT: Just to confirm, it isn’t Outlaw. I opened up the raw file in the Simulator outside of Outlaw and got ‘WARNING: failed to find image’ again.

Your folder structure looks correct, so this may be an issue with Windows or with Outlaw. The following is correct, to access an image within the “images” directory:

[lua]

local background = display.newImage(“images/background.png”)

[/lua]

FYI, “baseDirectory” doesn’t refer to your own folder, but rather a system folder like Resource, Documents, Temporary, etc. Normally you won’t need to tinker with this argument.

On the scaling thing, can you please show me your “config.lua” setup? There might be an issue with that.

Thanks,

Brent

I wouldn’t at all be surprised if it were Windows. Here’s the config file:

if string.sub(system.getInfo(“model”),1,4) == “iPad” then
    application =
    {
        content =
        {
            width = 360,
            height = 480,
            scale = “letterBox”,
            xAlign = “center”,
            yAlign = “center”,
            imageSuffix =
            {
                ["@2x"] = 1.5,
                ["@4x"] = 3.0,
            },
        },
        notification =
        {
            iphone = {
                types = {
                    “badge”, “sound”, “alert”
                }
            }
        }
    }

elseif string.sub(system.getInfo(“model”),1,2) == “iP” and display.pixelHeight > 960 then
    application =
    {
        content =
        {
            width = 320,
            height = 568,
            scale = “letterBox”,
            xAlign = “center”,
            yAlign = “center”,
            imageSuffix =
            {
                ["@2x"] = 1.5,
                ["@4x"] = 3.0,
            },
        },
        notification =
        {
            iphone = {
                types = {
                    “badge”, “sound”, “alert”
                }
            }
        }
    }

elseif string.sub(system.getInfo(“model”),1,2) == “iP” then
    application =
    {
        content =
        {
            width = 320,
            height = 480,
            scale = “letterBox”,
            xAlign = “center”,
            yAlign = “center”,
            imageSuffix =
            {
                ["@2x"] = 1.5,
                ["@4x"] = 3.0,
            },
        },
        notification =
        {
            iphone = {
                types = {
                    “badge”, “sound”, “alert”
                }
            }
        }
    }
elseif display.pixelHeight / display.pixelWidth > 1.72 then
    application =
    {
        content =
        {
            width = 320,
            height = 570,
            scale = “letterBox”,
            xAlign = “center”,
            yAlign = “center”,
            imageSuffix =
            {
                ["@2x"] = 1.5,
                ["@4x"] = 3.0,
            },
        },
    }
else
    application =
    {
        content =
        {
            width = 320,
            height = 512,
            scale = “letterBox”,
            xAlign = “center”,
            yAlign = “center”,
            imageSuffix =
            {
                ["@2x"] = 1.5,
                ["@4x"] = 3.0,
            },
        },
        notification =
        {
            iphone = {
                types = {
                    “badge”, “sound”, “alert”
                }
            }
        }
    }
end

I looked at the permissions for the folders involved. All of them have full access. So it’s not Outlaw (tested outside it and it still didn’t work) and it isn’t a Win8 permission issue.

Just as a test, can you rename the project folder to something without an “_”, like just “TurnTracker”?

Renamed it to FedComTDBasic. Ran the main.lua file using just the text file in the Corona simulator. Same warning about not finding the image. This might be of interest, it isn’t even mentioning the images/ part of the “images/background.png” code in the output window. It just keeps calling it “background.png”. Does that help?

So, any love on this subject? I’m kind of frustrated and on a deadline to learn all of this…

Hi @jabberwock,

Which build # are you using? Let’s try to step back and test the sample “HelloWorld” project. It’s located in:

CoronaSDK > SampleCode > GettingStarted > HelloWorld

The change you’ll need to make is putting the “world.jpg” file inside an “images” subdirectory, then changing its path in the “main.lua” code. Just one line. See what happens there, and don’t use Outlaw or any IDE, just do straight-up text editing (but not with basic Notepad, as I think that causes some isolated issues).

Brent

Hello World works. Today, everything works (even using Notepad, which is the only basic text editor I have), but not inside Outlaw. So maybe it is Outlaw, although I have no clue why that would be, since it is the exact same simulator using the exact same code regardless of what program turns it on.

Any idea on why the background is scaling up in what should be the ideal screen (the Galaxy SIII)?

Hi @jabberwock3,

I suggest that you use something other than Notepad. One of our engineers told me (once) that there’s some issue with how it saves Lua files or something. I can’t remember exactly the reason, but the message was pretty clear: “avoid it”. :slight_smile:

Instead, I suggest you get one of the text editors here, under “Choosing a Text Editor”:

http://docs.coronalabs.com/guide/start/installWin/index.html#editor

As for your image thing, it’s likely something with the content size that’s being chosen from the “config.lua” file, and how you’re displaying it on screen. If you’re using dynamic scaling, you should start using “newImageRect()” instead of “newImage()”: http://docs.coronalabs.com/api/library/display/newImageRect.html

Brent

Cool. newImageRect() worked, but only when I halved the 1280x720 pixel size of the png. According to the specs, an SIII should have a 306ppi screen with a 1280x720 resolution, but I’m only getting 640x320 out of it in the simulator. And I noticed if I just clear the info out of config, I get a perfect fit, but only in that particular environment. I feel I’m missing a trick here when it comes to mobile displays in lua. Any explanation?

Chances are, you need to tweak the “Ultimate config.lua” code a bit. What it’s doing, at the core, is figuring out the image suffix depending on the pixel size of the device, among other things. If you don’t want to go to that length, you can just use “letterbox” and use some easy convenience calculations to determine the “black bars” region on any device.

If your really targeting the SIII, try setting up a basic config with 320x640 as the core content area. Then do…

[lua]

print( display.imageSuffix )

[/lua]

…and see if it outputs “2” on the SIII.

Also, remember that the width is always the short side, even if you’re going for a landscape-oriented app. Never put in the width as the long side in the config.lua setup.

Brent

Ah! That makes sense! In my original config (before I found the ultimate one) I had made width 1280 and height 720. That explains the stretching. Knew it would be some stupid little thing like that.

Right, I’ll get a new editor, start over on the config and fool around with that last bit of info you gave me. I’ll get back to you if I run into something else. Thanks, Brent…

I don’t know why it doesn’t work for you.  I wonder if “images” is a reserved name.  My sub-directory folder for all my png images is named “PNG”, and it never fails to load a file from that sub-directory.

Naomi