How do I load image from url and create sprites at runtime from array?

0 favourites
  • 2 posts
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • Hi, i have a json with some data inside:

    - url of an image

    - position X

    - position Y

    - Id

    all these elements must create a different sprite at runtime, for example:

    http//:www.testimage.com/img1.jpg | 35 | 150 | 1

    http//:www.testimage.com/img2.jpg | 75 | 190 | 2

    http//:www.testimage.com/img3.jpg | 95 | 220 | 3

    at runtime i need the system create the exact number of sprite of same type but with a different image loaded according with the first value of the array, so the first sprite will be created at 35,150 and then the image img1.jpg will be loaded and shown, the same process for the second one, and the third one with the other values.

    So i tried to make a for each element loop to iterate and create the sprite, but the loopnever stops and continue foverer, i'm making something wrong maybe with the cycle?

    Any help will be appreciated.

    Thanks

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't know why your loop never stops, maybe you are running it on every tick? You should probably run it only once on layout start, or when JSON is loaded. There is a template in C3 which shows how to load and read data from JSON, check it out.

    Regarding images loading - each image needs to be loaded into a separate frame. So you need to create enough empty frames in the sprite, and set animation speed to 0.

    In runtime you need to create a sprite instance, set frame 0 and load image from URL. Then create another sprite instance, set frame 1 and load image. Repeat for all images in JSON.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)