Changing texture for one sprite changes it for all sprites using same texture

As I said in my last post, I said I was experimenting with modding and importing external assets from the drive. To change the sprite’s texture, I have to use resource.set_texture() and the dimensions have to be 2^N by 2^N, same as the current atlas dimensions.

This is fine and all and I can work with it, just the only problem is if I want to change the texture of one of the game object sprites.

Because the code is resource.set_texture(go.get("#sprite", "texture0"), buffer, headers), it changes the shared texture all the sprites use.

I’ve thought of 2 ways to solve the problem but don’t know how to do them or if they would work.

  1. Set the texture to a full picture of all the pictures and animations the sprite will use.

  2. Have different textures generated when object is created and destroyed when deleted.

If there’s a way I can do one of these or if there is another solution, please tell me, thanks.

Correct. If the texture (atlas or tilesource) is used by multiple sprites they will all be affected by the change.

We want this as well. This is the official feature request: https://github.com/defold/defold/issues/5948

Alright… So what should I do about it?

How many different sprite images will you need?

Well it depends, it’s moddable so basically as many as needed. But for an example, let’s say we needed 4 animations with 8 frames, so 32.

And how many different versions should be visible at a time? One solution is to use a tilesource with as many variants as you will be showing at the same time and update the sub regions of the tilesource.

Sorry, I don’t get it, when you say versions do you mean instances? If so then as many as possible. Can you show me an example with tilesources?