pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.71k stars 324 forks source link

Save and Load Texture Atlas. #1233

Open DragonMoffon opened 2 years ago

DragonMoffon commented 2 years ago

Save and Load Texture Atlas.

Offer a way to save a generated Texture atlas or part of one and have it be loadable later.

What should be added/changed?

A TextureAtlas.save() and TextureAtlas.load().

What would it help with?

Exporting games, and run speed since no texture writing needs to be done at run time.

A bonus benefit is sprites that are only ever on the GPU and their textures never need to be loaded.

Could be two parts. A png file and a Json file that could look like

{
"Source": ".../atlas.png",
"Size": [100, 100],
"Textures": {
    "light.png<params>": {
        "pos": [120, 145],
        "size": [100, 100]
        },
    ...
    } 
}
pushfoo commented 2 years ago

To my understanding, this would also be useful for caching loaded or pre-generated textures on disk. Providing functionality around that would be very helpful for projects like Brett's or the ambitious terraria clone a user was discussing on discord.

einarf commented 2 years ago

One challenge is: If you need the hit boxes for these textures that information will be lost.

Cleptomania commented 1 year ago

I'm pretty sure this is done now, I remember @einarf showing it working but I'm not sure exactly if it was fully added in or not.

DragonMoffon commented 1 year ago

@einarf, do you have an update on this? I know you've been doing a lot of work on atlases, so if there are any other relevant issues, maybe link this in?

einarf commented 9 months ago

There is a load/save_atlas in texture_atlas/helers.py that is currently not exposed. It's a very experimental feature. There's also a script in experimental using it. There are probably many issues, but it's a start.

einarf commented 8 months ago

This code needs updating. I commented it out due to the pressure to get 3.0 out. It can be enabled and tweaked later.