How do I spawn only one instance of a family object? [SOLVED]

0 favourites
  • 4 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Im trying to create a whack-a-mole type game. Everything game wise has been completed the only addition I want to make is to the characters that spawn. I have 5 characters in a family and currently have a random family object spawning at various positions on screen at various intervals. All is working fine as is. The thing is I dont want to have 2 of the same character on screen at the same time. I created a family instance variable called onScreen and set it to false. If the character is spawned it changes to true. After a certain amount of time the object is destroyed. The problem is this does not work, if the object never exists on screen it will not spawn.

    I read another forum post that suggested always have the characters off screen and set to false, then when you want the character to 'spawn' just change the position to where you need. This worked slightly - but every character in the family moved at the same time to the same position. Not one at a time. If I knew how to select just one family object I could continue with this approach.

    Does anyone know of a way to acheive this?

  • Hiya, families work well for applying logic to all objects at the same time and you will be fine to spawn a random object inside family when you opt to create the family object. When you start trying to identify individual object types within a family this is where it becomes difficult because you can't do it. For this type of logic you need to return to using the object types and instead of spawning a 'family object' you would do something like for example, pick a random number from 1 to 5 and spawn the object related to that number, if that object is already on screen or count > 0 then destroy it and run the randomizer again. You would need to break it down to check if Object A exists, Object B exists etc, not the family.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I was hoping not to have to go back to the individual objects but I guess thats the only way. Thanks for the reply!

  • If you only want to have 1 character of each type on the screen, then you can "recycle" them. Instead of destroying characters, move them off-screen. When you need to spawn, pick all off-screen family members and pick 1 random instance from them. You will also need to modify all other events, make sure that they are only picking active characters.

    It can also help to disable collisions for inactive characters, so that they won't trigger any "On collision" or "Overlapping" events.

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