dynamically adding / removing members from a family

0 favourites
  • 12 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Is there a way to add or remove sprites from a family at run time?

  • As far as I know it's not..

    What is it you are trying to achieve that you would need this for?

  • I will have 100 of sprites randomly falling at slow speed. I have added it to be part of a family. During the time the sprite is on the screen it should not be selected again. Ideas to implement it welcome.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can simulate adding/removing members from a family by adding a boolean to your family's instance variables called "Active". When you'd like to 'remove' an object from the family, set Active to False. To add it back again, set Active to True. To make this work, whenever you perform family specific events, add a condition to make sure that Active is True.

  • thanks. I will try it out today.

    Just to make sure the point, when Active is false for a sprite in the family, create object will consider this sprite, right?

  • It looks like adding a instance variable to control spawning of family members does not work. I have created a family of 10 sprites to randomly spawn to fall down the screen. I want to avoid spawning the same sprite if the instance variable "Active" not set ( while it is still falling). However it does not work. Given the link to my capx. Please check if I am doing any mistake.

    https://dl.dropboxusercontent.com/u/749 ... rds.caproj

  • I don't think you can use a family for this. I think you should create a spawning function. Create a array with 10 numbers in it, then when you spawn an object, pick one of those numbers and remove it from the list. if the number you picked was 1, spawn object1 etc. When an object1 falls off the bottom of the screen, add 1 back to the list and shuffle.

  • Absolutely. Before I posted the previous CAPX I implemented the method you said as alternative way.

    My sprites names are S1...S10. I am able to get the name of the sprite to spawn in a text variable. How do I spawn the object in the text variable elegantly?

    One do it is write events/actions for each sprite like text variable = "S1" --> Spawn object S1

    But this will lead to writing a line for each sprite I have. I am going to have 100+ falling sprites in each level.

  • I am finding it difficult to make the family feature to work while destroying object. I am trying to destroy member of a family using "Pick instance with UID" and not able to get it working.

    In the attached capx, click the red sprite first and then click on one of the green sprites. Both instances should be destroyed. It is not destroying the sprites for which I have provided the UIDs consistently. The logic is implemented within event No 14-20 in Lvl1 event.

    https://dl.dropboxusercontent.com/u/749 ... cards.capx

  • blackhornettechnologies.com/Construct2Stuff/fallingcards_BHT.capx

    Don't break up the trigger. Use subevents to check Touching, othewise when Touching=0, you set it to 1, then immediately check on the next event if it is 1 and do that code also.

    (I disabled some actions in event 7 as they were getting in the way of showing this fix).

  • Thanks. That a great Support!

    Please explain what was the problem in my case? You seem to have combined both the touch within one trigger. Does it keep the UID changed in my case.

  • As I said, you need to check your Touching state in the same event, otherwise you change the state and then immediately test for the new state, which it is, and so perform those actions too, setting the Start and End objects to be the same object, which fails the subsequent test and you are back to Touching=0.

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