[Solved]Destroying only 1 instance at a time by clicking

Get help using Construct 2

Post » Thu Aug 27, 2015 9:18 pm

Hi, My first Construct 2 question (regarding code) :)

I have a set up a system which destroys an instance by clicking on it. Only problem is when the instances are overlapping, clicking on them destroys all of them instead of one of the instances.

How could I go about making it so that by clicking on overlapping instances only 1 instance is destroyed? Currently they are on the same layer, I was thinking on adding them to different layers upon creation, then somehow deleting one by layer only.

Only what if I end up with 20 instances? I recon that the layer placement upon creation could be hard on memory.
The other idea is that each needs to be somehow labeled, then upon clicking the overlapping instances need to be checked and only 1 needs to be destroyed.
But then again I might be doing this backwards :P

I would appreciate if someone could shed some light on this matter.

Thank you.

Ps. At the moment it is only 1 type of instance that is being created.
Last edited by Solomon on Thu Aug 27, 2015 11:34 pm, edited 1 time in total.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Aug 27, 2015 10:48 pm

Did you try the condition > system > only once while true ?
B
8
S
4
Posts: 131
Reputation: 1,205

Post » Thu Aug 27, 2015 10:58 pm

Sprite:Pick top instance
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Thu Aug 27, 2015 11:00 pm

c13303 wrote:Did you try the condition > system > only once while true ?


Can't nest the 'destroy on click' in the 'trigger once while true' command... unless I'm doing something wrong?
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Aug 27, 2015 11:10 pm

blackhornet wrote:Sprite:Pick top instance


Darn, I can't seem to find that anywhere? Hmm... will keep looking...
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Aug 27, 2015 11:16 pm

@Solomon

Blackhornet is right - Pick Top/Bottom instance is the easiest way to get only one.
you can find it way down at the bottom of the object add event screen - under Z-order.

You can also use object.PickCount to see if you clicked on more than one. And you can do a For Each object to loop through all the instances clicked on and manually choose some other way which one (or more) to delete.
B
96
S
33
G
20
Posts: 438
Reputation: 17,665

Post » Thu Aug 27, 2015 11:33 pm

@AllanR and @BlackHornet

Wow thanks!!! So simple and so efficient :)
Once again thanks for your time and help!
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363


Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, brunopalermo, MaxxMunnn, mcscooter, Soluna Software and 25 guests