dynamically adding / removing members from a family

Get help using Construct 2

Post » Thu Apr 09, 2015 2:46 pm

Is there a way to add or remove sprites from a family at run time?
B
5
S
1
Posts: 41
Reputation: 466

Post » Thu Apr 09, 2015 2:52 pm

As far as I know it's not..
What is it you are trying to achieve that you would need this for?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Apr 09, 2015 3:15 pm

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.
B
5
S
1
Posts: 41
Reputation: 466

Post » Thu Apr 09, 2015 10:13 pm

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.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Fri Apr 10, 2015 12:41 am

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?
B
5
S
1
Posts: 41
Reputation: 466

Post » Mon Apr 13, 2015 3:01 pm

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
B
5
S
1
Posts: 41
Reputation: 466

Post » Mon Apr 13, 2015 6:02 pm

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.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Apr 14, 2015 12:52 am

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.
B
5
S
1
Posts: 41
Reputation: 466

Post » Wed Apr 15, 2015 10:47 pm

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
B
5
S
1
Posts: 41
Reputation: 466

Post » Wed Apr 15, 2015 11:59 pm

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).
ImageImageImage
B
71
S
21
G
211
Posts: 3,613
Reputation: 119,145

Next

Return to How do I....?

Who is online

Users browsing this forum: joliemoc, VulcanSpawnWolf, Yahoo [Bot] and 2 guests