How do I add the same array to multiple parent containers?

Get help using Construct 2

Post » Sat Apr 04, 2015 5:43 pm

I'm using an array to store data attribs for different sprite troops. I can edit one of the troops, add the array to the container. That works fine. However, I select another troop sprite, try to add the attribs array again to this container and the array is not available to pick. Why not?
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sat Apr 04, 2015 5:46 pm

You simply can't have two containers with the same objects, that'd be impossible to accomplish. The only thing you could try is having all your "troops" in a single sprite object with multiples animations.
B
62
S
26
G
24
Posts: 955
Reputation: 18,320

Post » Sat Apr 04, 2015 7:01 pm

Magistross wrote:You simply can't have two containers with the same objects, that'd be impossible to accomplish. The only thing you could try is having all your "troops" in a single sprite object with multiples animations.


Then how would each unique troop type have it's own unique array of attribs?
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sat Apr 04, 2015 9:23 pm

You can use one array and use one column for each unique troop. Or you can create a unique Array object for each troop.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Sat Apr 04, 2015 9:37 pm

Dalal wrote:You can use one array and use one column for each unique troop. Or you can create a unique Array object for each troop.


So put every troop into one big sprite sheet with multiple animations, one fore each troop. The sprite sheet contains a 2 dimensional array holding data for each unique troop in the sheet.

This could work. Probably the easiest way.

Thanks guys :)
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sat Apr 04, 2015 11:26 pm

Question on the resource consumption using this giant-all-in-one sprite: Doesn't each instance of the different troop types created carry all the other data with it? Won't this be creating an enormous, bloated sprite for every instance?
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Apr 05, 2015 3:03 am

I might have not understood properly, but I don't think you need an all-in-one sprite in the first place. It's less manageable, and no fun. I don't know what kinds of data you'd like to store, but in many cases, one array can hold the attributes for all your troops. For example, let's say you have Green, Yellow, and Red troops. Each troop has two attributes: Speed and Health.

Define constants as follows:
GREEN_INDEX = 0
YELLOW_INDEX = 1
RED_INDEX = 2
ATTR_SPEED_INDEX = 0
ATTR_HEALTH_INDEX = 1

Now, make sure your array has a width of 3 (the number of troops), and a height of 2 (the number of attributes per troop). Now, you can set/store an attribute for a given troop by using the Array (Set at XY) command, where X is your troop index, Y is your attribute index, and Value is the value you'd like to set it to.

For example, to set the Yellow troops health to 60, simply use Array (Set at XY): X = YELLOW_INDEX, Y = ATTR_HEALTH_INDEX, Value = 60.

You can read these attributes in a similar way.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053


Return to How do I....?

Who is online

Users browsing this forum: 13spongg13, Cappu, Yahoo [Bot] and 5 guests