How do I prevent spawning over already spawned objects

Get help using Construct 2

Post » Tue Aug 22, 2017 9:20 am

Hi,

I have a layer with 10 image-points and a family with 3 objects. I'm trying to spawn the objects randomly over the image-points randomly. The spawned objects are not moving but can be destroyed by another action. This works alright, but I am not able to prevent an object spawning over another one already spawned. If there is already one object spawned by an imagepoint, no other object should be spawned at that point.

Can anyone help me out? Thank

cheers,
held
B
5
S
1
Posts: 49
Reputation: 471

Post » Tue Aug 22, 2017 9:28 am

When I was making my rogue-like logic where it would generate a level, I did this by simply detecting if there is an overlap, destroy it, try and spawn it again. Another way might be to use your image-points as an object, give it a variable 'isUsed', set this to true when it is picked, then in the initial spawn logic make sure you pick an image-point that is 'isUsed=false'.
B
53
S
21
G
94
Posts: 2,425
Reputation: 55,563

Post » Tue Aug 22, 2017 9:43 am

Hope my example gives you an idea for non repeating chosen image point:
https://www.dropbox.com/s/gkmisirvgerai ... .capx?dl=0
ImageImage
B
134
S
55
G
24
Posts: 803
Reputation: 24,439

Post » Tue Aug 22, 2017 10:18 am

Thank you guys.

alextro: Puuh, pretty hard stuff for me. Sorry, but I don't get the code right now. But I'll keep on trying :)

plinkie: If I destroy the object immediately after spawning (in the case it overlapps an already spawned object) it destroys the object which is already there too. Which is not what i'm going for.

If I substitute the imagepoints by objects (spawner-sprites) and give them a variable, how do I address them in the random-spawn event? Right now, I'm working with:

system > every x seconds > Spawn-Object (the one with the image-points) > spawn family-objects (imagepoint random(1,10))

Thanks again
B
5
S
1
Posts: 49
Reputation: 471

Post » Tue Aug 22, 2017 10:38 am

Yes it gets tricky when you are trying detect which imagepoints are used but without using an overlap. You could literally set an instance var for each imagepoint I suppose and when it has been picked, then it is set to used. Then you would need checks such as 4 is picked, is 4=used, pick another imagepoint if 4=used.

Regarding the overlap checks, yes it will destroy both as you need to pick one of the objects in the collision. You can use a comparision nth instance in overlap checks. When an object overlaps an object, pick nth instance 0 is one of the objects, pick nth instance 1 is the other object. This is how you can differentiate between the two overlapping objects and destroy only the new one.

To use actual spawn points rather than a single object with imagepoints, you set the spawn points up with variable. Pick a random spawnpoint where the instance var is not set, then spawn the object.
B
53
S
21
G
94
Posts: 2,425
Reputation: 55,563

Post » Tue Aug 22, 2017 11:22 am

I will try my best with the spawn-objects rather than the image-points.
I set up the objects and instance var. But how do I pick a rondom object which instance var is set or not in the event sheet?
B
5
S
1
Posts: 49
Reputation: 471

Post » Tue Aug 22, 2017 11:28 am

It's the system condition, pick a random instance, then pick the spawner. Then add another condition spawner.variable=false.
This picks a random spawner where the variable is false. It will ignore all spawners where the variable is true (already has a spawned object). When you spawn the object, then set the variable=true, it will use the same picked spawner and adjust the variable to say it is now in use.
B
53
S
21
G
94
Posts: 2,425
Reputation: 55,563

Post » Tue Aug 22, 2017 11:55 am

Yes Sir! The whole time I worked with 10 different spawner-objects. Now, I'm working with 10 instances of one and the same spawner-object and coded as you advised. And...it works. Thanks a lot, really appreciate your help and your patience!

held
B
5
S
1
Posts: 49
Reputation: 471

Post » Tue Aug 22, 2017 11:59 am

No problem, good luck!
B
53
S
21
G
94
Posts: 2,425
Reputation: 55,563

Post » Thu Aug 24, 2017 9:15 am

It's me again. :)

I'm struggling with setting the isused variable back to false, so when the object above it is destroyed, a new one can spawn. Checking, if the object is not overlapping the spawner is not working. Can you or someone else help me out one more time?

Thanks!
B
5
S
1
Posts: 49
Reputation: 471

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000, saiprakash, SERGIOManOwaR, Themrcoolio, zenox98 and 10 guests