When i want to load a spriteframes.tres in code, it is really slow. It take at least 4 seconds to perform the load function. Did I do something wrong ?
Here is the code I use to test this function
At the top of you script preload the content as a const then use it later in your code.
Second more complicated option, Use a ResourceLoader.
# Create a cache dictionary
var _sprite_frames_cache = {}
func get_sprite_frames(actor_name):
var path = Global.PATH_ANIMATION_TECHNIQUE + actor_name + "/spriteframes.tres"
if not _sprite_frames_cache.has(path):
_sprite_frames_cache[path] = load(path)
return _sprite_frames_cache[path]
# Then use it
actor.set_sprite_frames(get_sprite_frames(actor_name))
Third option that might work, Background Loading. I’ve never tried it but ive seen similar stuff from my workplace and I’ve seen videos where people use it, Take my code with a grain of salt because its not something I’m super familiar with unlike the first two options.
var loader = ResourceLoader.load_interactive(path)
# Then handle the loading in _process with loader.poll()
Try some of these and let me know your findings, I’m sure the first will help but hopefully the next options will also be helpful at some point during your journey!
Sounds moderately big, if it uses a small spritesheet then maybe it got packed into the .tres as a long Base64 string. This can happen when files are moving around or if “make unique” is selected on the resource. Not sure the best way to re-link a SpriteFrames is, other resources can load pretty easily but you may have to slice the image again.
thanks, I will try all of your suggestion and see what would be good. It’s not seems to be a “first time load issue” because when a redo the animation again, it have the same issue when I switch the spriteframes. I already implement the background loading thing, but it’s not really a satisfying solution.
Not sure if I understand what you mean, but I use the “make unique” feature pretty often, so it could be a problem. How could you use smaller spritesheet in a spriteframe ? I just make many type of animation than contain like 30 frame, and when I check what in the .tres, is just described all the texture use in each animation.
If I use the .res format, of course it will be way smaller, but because I would generate this spriteframe by code to apply it for all the character in my game, I need to know the format. Perhaps I could after than convert the file as a .res after that, don’t know if there a simple way to do that and if it would change something about it the slow loading
image resolution “smaller”, I’d say you’re currently using a low-resolution spritesheet based on the file size; if the image is being embedded.
You can open the .tres file in a text editor to check for Base64 encodings, it will be a very long string of letters and numbers. If the file has a long Base64 string then your image is probably embedded, maybe through “Make Unique”. I think the easiest way to undo that unique problem is to re-create the SpriteFrames resource.
Ok, I test your three suggestions and do some research, and now I understand why it take so long. When you load a spriteframes, it seems that it also load all the frame use in all the animation, and in my case is pretty big, because I use spriteframe not only for some light animation of sprite, but also entire cutscene with background animation. And I don’t really need to store in the cache everything because it is for cinematic sequence purpose, not real time gameplay, so I have really long time to load everything I want after launching the first cinematic sequence.
So if i do your second suggestion, for the first time it take 5 second to load and after that, there no loading, so is okay. The third one is a possibility, but I would like a more dynamic approach.
What i would like to do, isn’t load all my animation directly, but only load the animation I want to display. For example, my spritesheet contain 100 animtation, if I could only load the spriteframe without loading any frame and after that, only load the frame for the animation “armagedon strike”. I don’t know if there’s a way to do so easily, what is create a program to generate one spriteframe for each animation contain in my current spriteframe. Like that, I could load “ghost_armagedon_strike_spriteframes.res”, and only load what i want to load. Pretty complex thing for a really simple thing I want to do, so I hope there a easier way to do so ?