Load image from url into two instances

@Bouh @ddabrahim
It looks like we can’t have more than one object with a url image at the same time.(without renaming all gd & js variables)
That’s okay in my case, but what i need now is to display the same image in a second instance or a second object. The “Pick all” can of course not work here.

Maybe this can be an extension or an “Online Sprite” object in the future. It’s not really good to use as it is.

I think the following features would be really cool to achieve something like this:

  1. Dynamic resource loading and unloading (Allow to chose when the resources should be fetched from the internet and when to discard the fetched resources data)
  2. Dynamically adding or removing resources
  3. Dynamically changing Sprites animations resources

That way you could

  1. Add your urls as resource dynamically
  2. Ask to load them after you added them
  3. Modify for instances selected via object selection the resource of their animations to the ones you just added and loaded.

I guess it was not meant to be used, we were just showing off how cool is that you can even do this with JS events :wink:

All you have to do is use a For loop and replace this code:

With this:

And then you can use as many instances as you want, it is going to change the image for all of them.
Here is the project:

1 Like

Perfect, thank you :slight_smile:

I am creating a sliding puzzle game (ExtremeSliderPuzzle | Play on gd.games) and the amount of images involved make it slow to startup. How it is setup now is that there is a sprite which has all the frames filled with the puzzle pieces plus a blank space. The code then square roots that and figures out what kind of grid to make 3x3, 4x4, etc. This makes it very flexible because if I want to upload a new puzzle I just have to upload the images and the actions will do the rest. Therefore I installed this extension. Now I can upload one image into the sprite but I fail to load more images into different frames of the same sprite. Is it possible to upload a complete directory? For example I would like all the pictures from Index of /Slides/MainCoonInForest this directory uploaded in one sprite.

I tried to search in the function configuration for the above code but cannot find it.
Could anybody help me in the right direction. It would make the game a lot leaner and also easier to expand to puzzles of anyone’s liking. For example custom made puzzle etc.

Sadly, GDevelop does not have a way to include images in an export without preloading them. If you do not mind copying your image files to the export folder every time, then you can

  • remove the images from resources so that they are not preloaded
  • use the load image from URL extension to load an image. Use a relative path (i.a. "my_image.png", not "/my_image.png"). You can use a string expression there to decide upon which image to load
  • copy the image files next to the index.html file in your export

If you want to be able to generate the list of images automatically, you can use a script to generate a JSON array with all of your files:
Install nodejs, run node in a shell in the project folder, and, assuming your images are in a subfolder images, run this script:

fs.writeFileSync("images.json", JSON.stringify(fs.readdirSync("./images")), "utf-8")

From GDevelop, you can load this JSON file with the “Load JSON resource into variable” extension. To pick a random one, assuming you loaded the JSON into the scene variable Images, you can use the following expression: VariableString(Images[Random(VariableChildCount(Images) - 1)])

1 Like

I solved it as follows:
Change the Parameter2 to type String.

This way I can load all the pieces in a repeat statement using a variable that changes the resource name. Depending on the size of the puzzle It will change all the needed resources. The rest of the code will remain undisturbed and functions the same this way.

Thank you for your help.

1 Like