How do I dinamically spawn an object which is member of a family?

0 favourites
  • 8 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I have a family "Enemy" which is composed of about 8 objects. Each object has an variable named "id" that defines what type of enemy the object is. (it goes from 1 to 8)

    I want to spawn an enemy given certain id dinamycally. Currently I'm doing something like this:

    var id = 3 // could be from 1 to 8

    if(x == 1) spawn enemy1

    if(x == 2) spawn enemy2

    if(x == 3) spawn enemy3

    etc...

    But this is obviously not scalable. Imagine that code with 50+ enemies. So I'd like something like this:

    var x = 2

    spawn(enemy with id x)

    Is there anyway to do this on construct?

  • Resolved!

    I was able to do what I wanted by using this awesome plugin made by rexrainbow

    construct.net/forum/extending-construct-2/addons-29/plugin-nickname-behavior-nickn-52043

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I suggest that you should use this plugin & behavior from Rex

    c2rexplugins.weebly.com/rex_nickname.html

    I am using this one and it works perfectly.

  • But this is obviously not scalable. Imagine that code with 50+ enemies. So I'd like something like this:

    > var x = 2

    > spawn(enemy with id x)

    >

    Is there anyway to do this on construct?

    Currently no, since the create or spawn action in construct is forcing you to visually pick an object.

    However if you really have multiple objects and the familly is just for the purpose of giving it 1 variable type of thing you can try instead of multiple sprites in 1 familly have 1 sprite in the familly, and multiple animations on that sprite named anim1,anim2,anim3, etc... and then when X = 3 spawn sprite at x y and set sprite animation to anim&X

    thats the only way i can think of that this might work.

    There is also this 2 year old post that kinda talks about the same problem, they seem to been solved it.

  • You can create objects by name in Construct 3.

    For example, you can do Create object "Enemy"&Type

  • OH yea C3 has that feature... Was thinking he needs it in C2, since its in C2 how do i section ... then my reply would make sense.

    Forgot about C3 :D above one fixes ur issue if your using C3.

  • I always got "wait for approve by moderators" when posting reply =-=

    I suggest that you should use this plugin & behavior from Rex

    c2rexplugins.weebly.com/rex_nickname.html

    I am using this one and it works perfectly.

  • You can create objects by name in Construct 3.

    For example, you can do Create object "Enemy"&Type

    I'm afraid that my project became too big to export to construct 3 now. So I'll have to stay with C2. :/

    I always got "wait for approve by moderators" when posting reply =-=

    I suggest that you should use this plugin & behavior from Rex

    c2rexplugins.weebly.com/rex_nickname.html

    I am using this one and it works perfectly.

    Ironically I found that plugin some minutes after I made the post, tryed to post how I handled the problem and got "wait for approve by moderators" as well. hahaha

    The plugin solved my problem! Works like a charm.

    Thanks to everyone who replied!

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