How I do load an Array

Get help using Construct 2

Post » Sat Nov 07, 2015 7:42 pm

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
B
2
Posts: 1
Reputation: 152

Post » Sun Nov 08, 2015 5:38 pm

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))

...to 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:

https://www.scirra.com/tutorials/4786/s ... 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! :)
B
22
S
9
G
4
Posts: 476
Reputation: 4,327


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests