How do I create an 'array' for sprites?

Get help using Construct 2

Post » Sun Feb 08, 2015 9:49 am

To start, I've only played around with C2 for a few days. I've read the manual. I can't seem to do a logic in C2 that I want to work.

I'm trying to test out a tower defense game. Let's say I have 20 waves/levels. In each level there will be 10 same enemies spawning. But each level will have different enemies.

The normal way I see from guides is that I need to create individual spawning/collision/targeted/dying/etc action for each enemies, so that would take a lot of same lines for each enemies and for every new type of enemy I add in the game.

Can't I just have a array for Sprite? There is for text & number, but I can't use those to manage my Sprites.

Example:
If I have an array for sprites, lets say spriteArray. So this has XYZ. I'm gonna use X only for this example.
OnLayoutStart:
spriteArray[0] = Ogre //=== Notice there's no quotation marks, so it's not a text value like "Ogre".
spriteArray[1] = Troll //=== I tried using text to try to spawn object matching the strings on my text, but there's no such thing in C2.
spriteArray[2] = Witch
spriteArray[3] = Shark
currentLevel = 2 //=== number variable

On Function Call >>> Repeat x10 >>> Spawn object spriteArray[currentLevel]

When I finish the level, I'm just going to add 1 to currentLevel and I can just use a function to call Spawn object spriteArray[curretLevel].
See also, if at some point, I decided to change a Troll to a Golem, if in the normal way, I would have to find each every line that has something to do with Troll and replace it with Golem, which I find inconvenient. If I have spriteArray, I can just change one line, the spriteArray[1] = troll on the start of layout.

Saving a lot of lines and time and a lot of managing when editing creep. I know about the Family feature, but it's not the thing, it doesn't do the job(Or maybe I'm not knowledgeable enough about it since I have no access to it to play with). Spawning a family creates random sprite, which is not what I want.

I can't seem to find a way to do this. Can help me find a way using this logic?

//===========================================
SECOND QUESTION:
When a bullet hits a Family of enemy sprites, how do I pick the individual sprite that got hit by the bullet? I want to save lines, time, and works instead of manually doing bullet1 colliding to enemy1 to enemy40+ and doing the same thing for bullet 2 to bullet 10+,( thats like 800+ similar lines alrdy). I don't mind the event sheet line limit for the free version, it's just this is inconvenient and impractical.

Thanks in advance.
B
7
Posts: 23
Reputation: 321

Post » Mon Feb 09, 2015 2:57 am

as far as i know you cant save objects-sprites inside arrays if you want to make it with less events and cleaner you need to use families and functions
an array can help you save strings or numbers (variables text) and then use them for things like enemy player or tower levelup

if you want to pick on families you have to pick by UID

read here https://www.scirra.com/tutorials/556/un ... o-families
Image
B
28
S
11
G
2
Posts: 139
Reputation: 3,299

Post » Mon Feb 09, 2015 3:07 am

Mabaet wrote://===========================================
SECOND QUESTION:
When a bullet hits a Family of enemy sprites, how do I pick the individual sprite that got hit by the bullet? I want to save lines, time, and works instead of manually doing bullet1 colliding to enemy1 to enemy40+ and doing the same thing for bullet 2 to bullet 10+,( thats like 800+ similar lines alrdy). I don't mind the event sheet line limit for the free version, it's just this is inconvenient and impractical.

Thanks in advance.


I thought the free version doesn't have Families. Or is this for when you get your licence? :)

Anyway if you have a Family of Sprites, and you have an 'on Family collision with Bullet' event, you will already have the Sprite (as a Family). So you could get Family.UID or whatever. If you really wanted to deal with the Sprite directly, you can 'pick Sprite with UID Family.UID' but if you do that a lot it that kind of defeats the purpose of Families.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Feb 09, 2015 3:47 am

Thanks for the replies, I've figured out on how to make an array-like for sprites, this would totally ease up my work.

@codah, yes, I said from the first question that I have the free one, I knew about the family in the manual and guides. I had C2 for a few days only, I need to get to know it better first. I'm planning to get license when I can and when I'm satisfied with C2 (Currently, I'm quite cool with it).
B
7
Posts: 23
Reputation: 321

Post » Sun Feb 22, 2015 9:21 pm

Mabaet wrote:Thanks for the replies, I've figured out on how to make an array-like for sprites, this would totally ease up my work.


Mabaet, would be nice if you could tell us how you solved it?
B
3
Posts: 9
Reputation: 193

Post » Mon Feb 23, 2015 4:11 am

Earthling wrote:
Mabaet wrote:Thanks for the replies, I've figured out on how to make an array-like for sprites, this would totally ease up my work.


Mabaet, would be nice if you could tell us how you solved it?


By using a nice neat trick with animation tabs which really, for me, makes the Family feature just bland. Maybe I'll write a tutorial of it soon.
I only used 1 object for all types of enemies & 1 object for all types of towers. I'm trying this out on a Tower Defense and it works well, I don't know for other type of game but I'm sure they can adapt the principle of this idea.

I just hope that a dedicated feature for this kind of logic be added soon.

In this example, I provided different bullets for a single tower(got lazy to make sample towers, but you'll get the point) and a bunch of different creepy crawlers as 1 object. This example is in its simple form, study it and play with it. I added comments at the events to explain. Hope you will like it.

It works like this: Remove spaces
youtu . be/mQSnXou8nn4?t=45s
You do not have the required permissions to view the files attached to this post.
B
7
Posts: 23
Reputation: 321

Post » Mon Feb 23, 2015 9:22 am

Mabaet go for license your money will be well spent on C2
B
250
S
39
G
15
Posts: 1,953
Reputation: 40,623

Post » Tue Feb 24, 2015 5:24 am

Lordshiva1948 wrote:Mabaet go for license your money will be well spent on C2


I hope so, I only have my spare times to get my hands on with C2. I will try to acquire license soon late next month where I'll have much more free hours/days and some fund for it.
B
7
Posts: 23
Reputation: 321

Post » Sat Feb 28, 2015 5:16 pm

Mabaet wrote:
Earthling wrote:
Mabaet wrote:Thanks for the replies, I've figured out on how to make an array-like for sprites, this would totally ease up my work.


Mabaet, would be nice if you could tell us how you solved it?


By using a nice neat trick with animation tabs which really, for me, makes the Family feature just bland. Maybe I'll write a tutorial of it soon.
I only used 1 object for all types of enemies & 1 object for all types of towers. I'm trying this out on a Tower Defense and it works well, I don't know for other type of game but I'm sure they can adapt the principle of this idea.

I just hope that a dedicated feature for this kind of logic be added soon.

In this example, I provided different bullets for a single tower(got lazy to make sample towers, but you'll get the point) and a bunch of different creepy crawlers as 1 object. This example is in its simple form, study it and play with it. I added comments at the events to explain. Hope you will like it.

It works like this: Remove spaces
youtu . be/mQSnXou8nn4?t=45s


Thanks a lot, Mabaet! Good job!
Have fun, G.
B
3
Posts: 9
Reputation: 193


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 18 guests