Spawn another object (by name)

  • There is a way to make you go to another layout by just selecting the layout you want to go to in the code. There is also an option to type the name of the layout instead of selecting it. But, you can also type a variable in there, so you can change the layout where you want to go to using a variable. Is there a way to do it with Spawn another object?

    This is useful when killing an enemy. When an enemy is destroyed, it spawns the object name that is written in an instance variable, aka it drops an item. Is there a way to do that or is it on the to do list

  • At the moment this is only possible with the third party plugin nickname.

    You could also add a variable check on destroyed and based on the variable spawn an object, but if you want to directly spawn by name, the nickname plugin it is.

  • The only way I can think to do it would be like this (https://dl.dropboxusercontent.com/u/108799982/Capx%20Demos/Spawner.capx) by using a number, because as LittleStain said you can't default spawn from name.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another solution, from the manual:

    ====

    Create object

    Create a new instance of an object type on a layer at a given position. If a Family is chosen, a random object type from the family is picked, and an instance created for that.

    ====

    So, add all your enemies to a family, and then spawn a new family member ;-)

    G.

  • CJK

    That will help spawning a random object, but I was under the impression topic-starter wanted the possibility to spawn a specific object by referencing it in an instance variable.

  • True :-)

    So, thinking about how I'd approach the "enemy drops an item" problem, I would try to:

    1) Create an "Item" sprite, with separate animations for each item type (e.g. coin, dagger, bomb), and naming the animations appropriately

    2) put the item type as an instance variable in an enemy

    3) upon killing the enemy, spawn "Item" object, then set the animation to whatever I need - e.g. "coin".

    Then, if your "Item"s have different functionalities, you can easily code these by checking what animation your "Item" is playing.

    This allows easy adding new item types, just by adding new animations.

    Cheers,

    G.

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