Treating runtime set textures like normal textures with sprites

Here, the title is confusing, but let me explain.

So, for a game, I’m working on using the game itself for modding instead of having people download source code, as I don’t want a possibility of easily making hacked clients.

For the actual sprites of the modded items, I decided to use the imageloader extension to do that. Then I just set the texture and we’re good, right? Wrong.

I’ve already talked about this problem in a previous post, but the problem with that is whenever I try changing an instance of that object’s sole texture without changing any of the others, it changes all of them, as they’re using the same texture.

I’ve thought of 2 solutions for this:

  1. Separate texture for each instance
    Biggest problem with this though is that this might take up some ram space, causing it to slow down.

  2. Change the texture to a full “atlas” of all the different pictures the instances will use, and changing the sprite images normally, as if they were in the game files when built.
    This would be what I do, but this would require somehow taking an external image (and possible atlas file) and somehow trying to turn that into a texture file.

Does anyone know any ways I can manipulate texture files to do this? Or what the information in a texture file means? Or alternatives I can use that could maybe use tilesources and how to manipulate those? Thanks.

What if you use a tilesource of a predefined size with created “animations” (one frame/tile each) for each time and then at runtime change individual tiles of the tilesource? The advantage of using a tilesource is that the images are on a fixed grid which should make it easy to update individual tiles.

I just want to note that the caveat of 1) isn’t that it takes more memory, but that each sprite will use a different texture, so they will end up in different batches effectively generating a lot of draw calls.

Regarding 2)
You can create an atlas offline, with the (dummy) images of the same size.
And then at runtime, you can easily update the sub image of the texture since you know where that image is in the texture.

This does seem like a good idea, how could I update a tile during runtime with the results of the imageloader extension?

Alright, can you give me an example o how to possibly do 2?

@Mathias_Westerdahl, could you elaborate on this please? And how would this work with multiple objects?

The atlas texture creation is deterministic.
So if you add 16 images of equal size you’ll get a texture where each image is where you’d expect.
E.g. image 1 is in the top left corner, image 2 is next after that, and image 16 is at the bottom right corner.

Knowing this, you can change the data of your texture you wish to set (you still have to set the full texture, not just a sub part).
So you need to be able to load the images at runtime.
And you need to have created a dummy atlas with the correct size and layout at edit time.

Ok, then I set all the atlas images/animations beforehand and just change it. It would be more convenient if we just created a texturec file with the atlas and pictures and imported it into the game though.