How to work with an array of sprites

Get help using Construct 2

Post » Mon Dec 14, 2015 11:14 pm

I created an array of sprites. I want to be able to create a random sprite from this array every three seconds. When I select 'create object' Construct does not give me the option to select an item from the array. Can this be done in Construct? Can anyone help me out with the syntax? Thanks!
B
3
Posts: 3
Reputation: 181

Post » Tue Dec 15, 2015 1:59 am

I think the easiest way to do it would be to have one sprite with a bunch of frames. That way you create the same object, but change the frame based on the array. Otherwise, you'd have to put them all in a family and reference things that way (I believe).
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Tue Dec 15, 2015 12:16 pm

Try using Rex_nickname plugin. It allows you to create an object based in a given nickname (this nickname could be the value stored in the array).
B
73
S
19
G
1
Posts: 107
Reputation: 5,070

Post » Sat Jan 23, 2016 11:51 pm

What you'd do is:

Code: Select all
Every 3 Seconds
 > Set variable "var_randomsprite" to random(Array.Width)
 > Create object "Sprite"
 > Set Sprite.Width to Array.At(var_randomsprite, 0)
 > Set Sprite.8Direction.MaxSpeed to Array.At(var_randomsprite, 1)


And so-on - you choose a random number first, then create your sprite with values according to the entry held at that value on the array. It's a bit of a mind-squeeze getting your head around arrays - but if you can master these and working with loops, you're pretty much set.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sat Feb 13, 2016 1:28 pm

You can not create objects during runtime.
You always create an instance (of an object) during runtime.
Assuming dat we speak about animated sprites, then every sprite will have one unique object assigned to it.

Every object needs to be in the layout before runtime.

Therefor, create a placeholder object for every sprite in the layout. Assign a sprite to it from the array during an 'on layout start' event.
(if you want a .cap from that stap, then post de .cap with the array)

Then it is easy to use Construct's family-pick-system to create random things. As in this .cap
https://
drive.google.com/file/d/0B1SSuCVV8v74Tl95dG43a1lXbXM/view?usp=sharing

Greetings
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests