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

0 favourites
  • 7 posts
From the Asset Store
Click! Click! 136 click sounds for your video games or media projects
  • 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

    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.

  • Did you try the condition > system > only once while true ?

  • Sprite:Pick top instance

  • 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?

  • Sprite:Pick top instance

    Darn, I can't seem to find that anywhere? Hmm... will keep looking...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • AllanR and blackhornet

    Wow thanks!!! So simple and so efficient

    Once again thanks for your time and help!

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