Factory > load image from web

Hi guys,
I have a Collection with a sprite. Image is loaded from main.atlas using Default Animation.
All images are in assets folder.

How do I use image from web?
I looked at image.load and imageloader.load() but confused as to how this applies to Collections and Factories.

The Image Loader extension allows you to load an image from for instance the internet or loaded from disk and convert it into a buffer object. You can use the buffer object to replace a complete texture/atlas used by a sprite.

What do you mean by this? Objects spawned from factories are not treated differently when it comes to changing the texture. Keep in mind that you replace the entire atlas/texture. This will affect all sprites which reference the same atlas.

2 Likes

Cool,
I guess my next question is:
How do I load multiple images from web to replace entire atlas/texture?

I guess I need to create “cards.atlas” with default images for each playing cards ( 52 images )
Then when user selects different deck. I go download images from web.

Is there a way to replace images in “cards.atlas” with all 52 new images?

If you want to replace the entire deck of 52 cards then my suggestion is to have all cards in a single image and use the image as a tilesource. That way you know exactly in which order the cards are laid out in the images. So something like this (from Kenney.nl)

If the above is the default deck and the user changes deck you download a single new image with the cards laid out the same as in the default deck. When the image is downloaded you use the Image Loader extension to get a buffer object. And you use the buffer object to change the texture of a single card instance, which will affect all cards referencing the same texture.

local data = download_image_from_the_internet()
local image_resource = imageloader.load({ data = data })
local resource_path = go.get("any_card#sprite", "texture0")
resource.set_texture(resource_path, image_resource.header, image_resource.buffer)
7 Likes