How I do load an Array

0 favourites
  • 2 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi,

    I have 5 images A.jpg, N.jpg, A.jpg, D.jpg, E.jpg and an Array Object of five elements

    I want to load the Array with the name of the pictures randomly. how can I do ?

    thank you

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi there,

    I'm not entirely clear about what you want, but I'll have a stab at a couple of possible solutions that might be of use:

    1) If you simply want to be able to display a random image then just add the 5 images as frames to a sprite and use this action:

    set object frame to floor(random(5)) display a random image. In this situation you don't need to worry about the names of the images. You will need to ensure the animation speed is set to zero, or that you have stopped the animation to stop it playing through all the frames.

    2) If you need to keep the image names (for some reason), and want to randomise the images and ensure that they keep that randomised pattern without repetition of images until all images have displayed:

    i) add each image as a separate animation to a sprite, naming each animation after the image

    ii) add the animation names to an Array object then shuffle the array using a method such as this one: ... ur-project

    iii) If you want to step through the images in the shuffled order, somewhere in your code you will want a condition like this:

    On event:

    if n <5, add 1 to n (this steps up the current index value)

    else n = 0 (resets n once n has stepped through all values)

    Sprite Set Animation : array.At(n,0,0)

    ...where variable n is the index in the array of the animation you want to display.

    Hope that helps! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

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