Sorry, I’ve spent an hour checking forums and I know that I can’t use string variable (path to texture) as a property, but I can use url. I just can’t pass it to property.
One of a dozen tries. This one gives “go.set failed with error code -10”
local path = "/data/".. type.. "/" .. number .. ".jpg"
go.property("texture", resource.texture())
go.property("texture", msg.url(path))
All my other tries end up with GO does not have any property called ‘texture’.
I’ll experiment a bit to figure this out. But it makes sense that you get a “resource not found” error if you change texture using code and specify a dynamic resource hash like hash("/foo" .. count .. ".jpg"). The build pipeline will not know which foo*.jpg to include. We still need to know about all resource up front to be able to include them in the application bundle.
Oh, got your point. Just made another property “texture2” to “store” correct path there. It transformed my hash: [/data/cres/e1.jpeg] to hash: [/data/cres/e1.texturec] and dynamic texture change worked after that.
Should I somehow parse all my images to that format? I have about 200 images there. =)
Gives the same error. Looks like it can handle “jpg” only when unique property is being initiated.
And looks like it doesn’t matter if I create texture property inside local function.
Maybe I should also ask what it is you want to do? You have many images/textures, and you wish to, at run-time, select one to use on a model? Is that correct?
What about something like this:
go.property("t1", resource.texture("/data/cres/01.jpg"))
go.property("t2", resource.texture("/data/cres/02.jpg"))
go.property("t3", resource.texture("/data/cres/03.jpg"))
go.property("t200", resource.texture("/data/cres/200.jpg"))
function init(self)
local t = go.get("#", "t" .. tostring(3))
go.set("#model", "texture0", t)
end
You should probably create a bash script or something to generate a script file containing all of the go.property() entries though. Or maybe an editor extension script could do it for you.
If a file isn’t directly referenced in a resource (atlas, tilesource, model, spine etc) or if the resource isn’t used it will not get included in the final build. This is by design. You as a developer should not have to worry about your app containing unused files. Everything in the final bundle is referenced by some component and could therefore at some point be used by your code.
You can use Bundle and Custom Resources to include arbitrary files that you can load at runtime. But I’m not sure if you can load one of those and use it as a model texture.
Yes it’s in Custom Resources. But I’ve just found a solution =) I’ll add those textures to object atlases and replace models with simpler sprites. It’s even better then the original concept.