Spawn objects on custom spots

Get help using Construct 2

Post » Mon Jul 03, 2017 5:27 am

Hello,
So I have 2 slots in wich I want to spawn one object. My problem is that if one slot is occupied how do I make the object to spawn on the other one. I have to mention that there can be 10 slots and I want to spawn the object on the ones that are not occupied... one by one. The idea of the game is to have 1 plate of food and when I press a button the plate spawns random on one of the slots but not on the slots that already have a plate on them. And when one spot is cleared it should be again available for spawning.

Thank you and have a nice day
B
11
S
1
Posts: 35
Reputation: 533

Post » Mon Jul 03, 2017 8:04 am

Hello o/

There are many ways you can do that, and the best way to do it depends on what you are looking to achieve on the rest of the game. So I will give you a few ideas, and you try to see if any of them works with what you are trying to do, and if they don't you come back here and try to be a bit more specific on what's going on on that game of yours.

First thing I would try is a "system > for each" and make the slot spawn the object. This will select each slot once and spawn the object for each one of them.

Another look would set at the slot properties a variable to define if the object is occupied or not. After that every time you want to spawn something you go "system>pick by comparison" and compare the variable of the slot with the value that tells if it is occupied or not.

And another way, that I wouldn't suggest that much, but it can still work is trying to check if the slot is overlapping the object you want it to spawn, and if it is not then spawn it.

Again, see if any of this helps and if it doesn't just come back here o/

Good luck
B
17
S
7
Posts: 280
Reputation: 2,522

Post » Mon Jul 03, 2017 11:03 am

@PreacH Would this work for you?:

https://www.dropbox.com/s/why3eeheyjhd7 ... .capx?dl=0

Tap any key to add a random plate.
Left click a plate to remove it.

Tapping a key populates calls a function that populates the array with the UIDs of all plate objects that have an animation frame of 0, then picks one at random and assigns it a random plate frame (excluding 0).

You can scale this by adding more plate objects to the layout, no need to adjust the code.
If you want more plates of food you can add extra frames to the animation.
B
20
S
9
G
4
Posts: 473
Reputation: 4,260

Post » Mon Jul 03, 2017 11:13 am

@mekonbekon Your example is perfect for what I need. Thank you very much for this and thank you @RayKi as well for the great ideas
B
11
S
1
Posts: 35
Reputation: 533

Post » Mon Jul 03, 2017 11:27 am

@PreacH You're welcome :)
B
20
S
9
G
4
Posts: 473
Reputation: 4,260


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 44 guests