How do I create an 'array' for sprites?

0 favourites
  • 9 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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.

  • 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

  • //===========================================

    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.

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

  • 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?

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Mabaet go for license your money will be well spent on C2

  • 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.

  • >

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

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