Can't replace image in atlas

I’ve been trying to achieve the Modify atlas example in my own project for modding support with no luck so far. It seems like the example code gets the wrong UV coordinates, especially if the target image isn’t on the top-left of the atlas.

Downloading and running the example as-is works fine:

But adding random junk to the atlas breaks it:
image


If you look closely, you can see the bottom part of the green spaceship got overwritten.

Here’s a small demo project I made to test this out and make sure I wasn’t going crazy:
imagereplace.zip (4.0 KB)
The code tries to replace the orange-and-blue logo with the blue-only logo. It works when the orange-and-blue logo is the only one in the atlas, but it ends up replacing a totally different part of the atlas when another image is added.

I’m not sure whether this is a bug in the engine or just some bad example code.

EDIT: Forgot to mention I’m on 1.8.1, if it’s important.

I think the example code is bad:

Related: Add margins to the left and top edges of the atlas. by AGulev · Pull Request #8657 · defold/defold · GitHub

1 Like

I’ve already tried removing that offset, but it didn’t help. The image is off by way more than just 6 pixels.

Ok, please create a ticket on GitHub and link it here. It seems like something we should look into.

1 Like

Do you want it in the main repo or the examples repo?

Doesn’t matter. As long as it is easy to reproduce.

Done!

2 Likes

Hello i had the same problem, after some tests , i figured out that the “x and y” parameters for the texture parameters is relative to the atlas bottom left so i come up with something like this :

 local atlas = resource.get_atlas("/examples/resource/modify_atlas/modify_atlas.a.texturesetc")
local tex_info = resource.get_texture_info(atlas_data.texture)
local uvs = atlas_data.geometries[1].uvs
local x = uvs[1]
local y = texture.height - uvs[2] 

If it still doesn’t work, you should check directly in the atlas the position of your animation/image , sometimes it may be rotated automatically( laying down ) to optimize space in atlas.

Hope it help :slight_smile:

2 Likes

That seems to do the trick, thanks!

I think there might still be a bug in the engine code regarding this, I don’t think you should have to invert the uvs like this :thinking: oh well, glad that there’s a workaround for now