I’m building a game where I want to download images from a back end which isn’t ready.
Instead, I’ve added them as project files so I can use AJAX to retrieve them.
When the back end’s ready, I’ll update the AJAX request’s URLs.
I also want to save the images to local storage.
(I’m using a Binary Data object for the local storage and AJAX requests.)
So the flow is:
- Does the image exist in local storage?
- No? Request it from AJAX
- When it’s returned from AJAX, write it to local storage.
- When it’s written to local storage, request it back.
- If it does already exist in local storage, request it.
- When the request from local storage is complete (from either of the two routes above) create sprite.
- When the sprite’s created, load its texture from the picture returned from local storage.
This works for the first image loaded, but when it does it for the second, it also overwrites the texture of the first and so on. I'm picking the sprite to load the texture into based on "on created" and confirm that only one sprite is selected by writing pickedCount to the console.
Is this a bug or am I doing something wrong?
Minimal reproducable project:
drive.google.com/file/d/1Jr40AlfrJyxgY3jSjtBM37ua876FNqTH/view
EDIT - I though reusing the same binaryData Object for both AJAX and local storage might be the issue, but if I remove local storage entirely and just download the file every time and load it straight into the sprite, the same thing happens.
EDIT 2 - Ok, I'm being dumb - instances of a sprite can't have different textures.
So can anyone suggest how I can best handle this? Different frames? If I need to download 50 images, would that cause size/performance issues?
EDIT 3 - editing that test project to use tiled backgrounds instead of sprites appears to work - will try that for real...