Changing texture for a tilesource at runtime

Hello together,
I’m new to Defold and although I’ve read quite a bit here on the forum and in the manual, I have to admit that I still don’t fully understand all the correlations. But I have the will to learn :wink:

My goal is to load a different image into a tilesource at runtime each time. For this I have installed the image loader extension and I also get correct info after loading an image.

I’m unsure if it’s currently possible to swap out the textue of a tilesource at runtime.
However, currently I simply get the error “The resource was not found”. Is it not correct to address a tilesource in this way? Or is the texture accessible via a different path?

Here is a screenshot:

Thanks for any tips!

1 Like

Yes, you need to specify the path to the compiled resource. In your case I believe it will be something like /assets/art-image.t.texturesetc. Both atlases and tilesources will become texture sets when compiled. The .t. in art-image.t.texturesetc indicates that it is a tilesource, while it would have been named art-image.a.texturesetc if it was an atlas. The “c” at the end identifies it as a compiled resource. You can have a look in the build folder to see the correct filename.

1 Like

Thanks for the info, I have found the file and corrected the path!
However, now there is a crash, it says:
Assertion failed: (buffer), function LoadMessage, file ddf.cpp, line 163.

But the result of image_loader() seems to be correctly filled with the file (a .jpeg):
{ --[[0x1078cec50]] buffer = buffer.buffer(count = 614400, version = 0, handle = 65536, { hash("pixels"), buffer.VALUE_TYPE_UINT8, 3 }), header = { --[[0x1078ceca0]] height = 960, type = 0, format = 2, num_mip_maps = 1, channels = 3, width = 640 } }

Are you passing in an entire table as the argument or the actual buffer handle? Maybe if you could share the code from loading the buffo setting the texture we can make sense of it :slight_smile:

I had followed the examples and pass “image_resource.buffer”.

That would be great! Attached an demo project reduced to loading the new image: (263.1 KB)

There’s also a new example on how to update a sub region of an atlas: Modify atlas