Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Can't load images
Started by nosoyhackercodigo Jun 03 2019 04:59 AM

11 replies to this topic

Best Answer nick_sherman , 03 June 2019 - 11:14 PM

A few questions:

 

Is there really a file called M.lua in the main project directory? Or is this just example code? 

 

Also, what is 'rectOptions'? If it's a table, that won't work - the parameters of newRect are not passed inside a table. You'd have to pass rectOptions[1], rectOptions[2] or rectOptions.width, rectOptions.height etc. depending on how the table is structured.

 

 

 
-- module.lua
 
local m = {}
 
  m.path = {type = "image", filename = "path/to/file.png"}
 
return m
 

 

 

 

 
local myModuleHandle = require("path/to/module")   -- I must be called module.lua and in the folder path/to/
 
local image = display.newRect(100, 100, 100, 100)
image.fill = myModuleHandle.path
 

 

If that still doesn't work, verify you can create an ordinary display.newImageRect using the same image path.

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

Hello, everyone.

 

I'm having a hard time trying to figure out how to load the images on the build for Windows.

 

I am doing something like this:

 

object.fill = "here goes the image path"

 

But get an error, cannot find the image I'm requiring to.

 

Is this an error related to file management?

 

 



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,979 posts
  • Corona SDK

Have never had any issues with Windows builds and images. Double-check the filename, because they will be case-sensitive, including the extension and folder names.



[TOPIC: post.html]
#3

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

I'll see that in a moment...



[TOPIC: post.html]
#4

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

It's happening because of the image being declared in another file module maybe?



[TOPIC: post.html]
#5

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,979 posts
  • Corona SDK

I don't know, we'd need to see some code.



[TOPIC: post.html]
#6

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

The computer I'm currently using for Corona projects is really far from me so unfortunately can't do that right now...

 

But when I reach home, I'll show you the code.



[TOPIC: post.html]
#7

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

It's like this:

local moduleContainer = require("M")

local image = display.newRect(rectOptions)
image.fill = moduleContainer.path

--In moduleContainer.path

{
    type = "image",
    filename = "path/to/file.png"
}


[TOPIC: post.html]
#8

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,979 posts
  • Corona SDK

  Best Answer

A few questions:

 

Is there really a file called M.lua in the main project directory? Or is this just example code? 

 

Also, what is 'rectOptions'? If it's a table, that won't work - the parameters of newRect are not passed inside a table. You'd have to pass rectOptions[1], rectOptions[2] or rectOptions.width, rectOptions.height etc. depending on how the table is structured.

 

 

 
-- module.lua
 
local m = {}
 
  m.path = {type = "image", filename = "path/to/file.png"}
 
return m
 

 

 

 

 
local myModuleHandle = require("path/to/module")   -- I must be called module.lua and in the folder path/to/
 
local image = display.newRect(100, 100, 100, 100)
image.fill = myModuleHandle.path
 

 

If that still doesn't work, verify you can create an ordinary display.newImageRect using the same image path.



[TOPIC: post.html]
#9

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

The code I provided was just an example.

 

But now it's working!

I replace the part code with the image path to a whole module and now it works.

 

But really wanted to make it work without requiring a module.



[TOPIC: post.html]
#10

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,979 posts
  • Corona SDK

Well I only included the module side as that was what you're example was doing. Why were you using a module in the first place?

 

You can get the path string from anywhere - hard-code it, from a variable, from a table, from a variable within another module, from a table within another module, from a variable nested 12 modules down, from a network call, from a text file - it's up to you. Whatever fits the way you want to build your app. 



[TOPIC: post.html]
#11

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

I think the reason for this is the high dependency of functions between objects



[TOPIC: post.html]
#12

nosoyhackercodigo

[GLOBAL: userInfoPane.html]
nosoyhackercodigo
  • Enthusiast

  • 70 posts
  • Corona SDK

But thanks anyway!




[topic_controls]
[/topic_controls]