It would be nice to define atlas size with any dimensions, not just power of two.
Sometimes memory and texture size are more important, e.g. for HTML5 games.
E.g. we have a number of 1920x1080 backgrounds, so we have to put each one in 2048x2048 atlas or slice and combine them somehow (not very convenient )
If you don’t mind extra draw calls you can always use them as is.
If they are in a gui you can always add images (don’t think it works in collections, but maybe?) directly without adding them through an atlas, you will have to edit the gui as text file to do this I think.
You could also load the images as resources. But if you add them as resources they will not be compressed with the .texture_profile. But you can force that if you add all png images to a gui (you will never load this gui into the game, it is only to fool the engine to think that the resources are used this way). I did this with a python script.
script
import os
import hashlib
project_root = "/Users/mattias.hedberg/porjects/force_compression"
gui_file = os.path.join(project_root, "main/force_compression.gui")
texture_folder = os.path.join(project_root, "assets/resources/textures/")
textures = ""
names = []
for root, folders, files in os.walk(texture_folder):
for image in files:
if image.endswith("png"):
full_path = os.path.join(root, image)
name = hashlib.sha1(full_path.encode('utf-8')).hexdigest()[:5]
textures += 'textures {\n' + 'name: "{}"\n texture: "{}"'.format(name, full_path.replace(project_root, "")) + '\n}\n'
gui_file_string = 'script: ""\n{}adjust_reference: ADJUST_REFERENCE_PARENT'.format(textures)
with open(gui_file, "w") as f:
f.write(gui_file_string)
But when I think about it I am not sure if Defold adds extra padding to make them power of two. Don’t think so but maybe someone can confirm?
Note that textures added as custom_resources not being compressed have been brought up before and is marked as “will not fix” with this explanation.
“This feature would increase the size and complexity of the custom_resource functionality a lot. custom_resources was initially implemented to support loading of small data objects such as json/xml/html and not for images and textures.
Including custom textures should be solved in another way, and is not suitable for the custom_resources solution.”
resource.set shows an example of setting it with go.get(), but I haven’t actually testet to load resources myself.
No clue
I agree, shouldn’t need to compromise on quality for something like this
Also, note that I mentioned it as potential workarounds until it gets added, not as solutions.
I definitely think there should be a “Force power of two” checkbox (that is ticked by default) on the atlases.
You can make an extra GUI render predicate which is placed behind game assets in your render script. This is what I do for dynamic backgrounds in one project.
You can load a PNG from wherever, get it as a buffer and use it to change the contents of a texture using resource.set_texture(). Since we’re talking about background images here I guess you’ll only show one at a time? That would require a single atlas with a single image of the correct size. You can use my PNG extension to load the image and get it as a buffer or do it yourself using image.load().
out of curiosity, there’s a way to set also animation data of an atlas? To draw animated sprites I use Aseprite - and for my C code game I made a library to read data from its file format, to create an image atlas on the fly and to create animation information from its inner animation data. I’m wondering if there’s a way (with a native extension) to do the same.
Of course, if there’s not, I can make a tool to create png and json .atlas file - and to simply use them in my games - so, as I said, is more a curiosity than a request
While you could potentially change texture at run-time (and this will be much easier soon) you still have the issue of creating/changing animation data at run-time. This is currently not possible.
Your best bet would be to convert you Aesprite data into an atlas or tilesource as a manual prebuild step.