How do I select just the top sprite?:

0 favourites
  • 13 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • Two sprites overlap each other. If I click on one of them sprite specific actions happen. Problem: If I click in an area where both sprites overlap the action of the bottom sprite is performed.

    Possible solution: Create an array. All touched sprites will be listed in one column and their layer in another column. Now sort the list by layer and choose the object with the highest layer. Now perform just the actions for that object.

    Are there any better solutions? If no, how would I create such an event in CS2?

  • You don't need to do anything as complicated as that, when two sprites overlap you can reference them as one being 0 and the other being 1. Look at ashley's response here about picking

  • Or even simpler add the common condition "Pick top instance" from the "Z Order" category which is specifically dedicated to this kind of issue.

  • In a scenario like the one below. How would I solve the problem?

    On left mouse click resize the sprite.

    The event sheet:

    Layout:

    If I click in between the objects both of them resize but I just want the green box to get bigger and not the pink one to get smaller.

  • You can do this with one event I think. Add your objects to a family.

    On left button clicked on Family

    Condition: Pick top instance > Family Set scale

  • As I couldn't find a way to resolve this issue by using a Mouse event, the issue was resolved by using a Touch event instead. <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

    What was needed

    1. When more than two stacked objects are clicked, only the top sprite's event must be triggered.

    Solution

    1. On touched (Object1).

    2. (Object1) - Pick top instance.

    3. (Object1) - Scale 1.5.

    Then I had to make sure a stacked object located below was also 'tappable' with its own event.

    1. On touched (Object2).

    2. If (Object1) is not touched, scale (Object2) 0.5.

    So far, this was the only solution that was able to find, after more than an hour of research.

    At first, it looked very simple to resolve, but it was a difficult one.. I've also spent hours on the same issue in the past, but I couldn't find the answer at that time.

    Check out my example file. <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

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

  • That method gets crazy out of hand with more than 2 sprites, you'd have to put If Object 1 is not touched, if Object 2 is not touched etc infinite amounts of conditions for every overlap check with different object types, plus that still wouldn't work with multiple instances of the same object, it assumes SpriteA is always on top and then SpriteB etc as it checks them in order. My above method handles any number of overlapped objects with one event.

  • That method gets crazy out of hand with more than 2 sprites, you'd have to put If Object 1 is not touched, if Object 2 is not touched etc infinite amounts of conditions for every overlap check with different object types, plus that still wouldn't work with multiple instances of the same object, it assumes SpriteA is always on top and then SpriteB etc as it checks them in order. My above method handles any number of overlapped objects with one event.

    Yes, but I have found the solution as per punktum's request.

    1. Two sprites.

    2. Click an area that is overlapping.

    3. Only the top sprite's event is triggered.

    I've also experimented with the Families option, hence the 'Family1' object in my example file, but decided not to venture into that field any further after spending too much time on a new issue.

    The issue I encountered was trying to trigger two different event actions (Green = scale x 1.5 & Blue = scale x 0.5) as Families, so that option required more than one set of extra code to allow the Blue to be picked as 'Pick top instance'.

    When I encountered a similar issue in the past, I ended up spending days trying to find an answer without success.. so after spending slightly over an hour earlier today, I've decided to provide a solution on what punktum initially asked and step off; as that's better than giving him theological instructions without providing an actual example file on what to do on his own.

    This issue appears to be simple to resolve, but it's not.

    If anyone else could take over the coding, that would be great, as I want to learn too.

    I have a feeling that an easy solution will be found with functions and arrays that I'm not fond of.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The answer is out. Check out 99Instances2Go's post below.

  • That's exactly the same as what I posted above. Click on Family > Pick top instance. The non-family .capx is pretty much what you posted but like I said it gets out of hand with the comparisons on loads of objects.

  • That's exactly the same as what I posted above. Click on Family > Pick top instance. The non-family .capx is pretty much what you posted but like I said it gets out of hand with the comparisons on loads of objects.

    Yes, plinkie. You were right. Thank you very much for the information.

  • but like I said it gets out of hand with the comparisons on loads of objects.

    That's one major problem in our project.

    Another problem we have to solve is that all our objects have different actions. In our case a tap on object A should trigger sound A and tap on object B should trigger sound B.

    We can not apply a action to the family as a whole because of that.

  • punktum

    I've got a fix for this as well. Create a family instance variable i.e. sound. On all objectA set it to 1, on all objectB set it to 2. Under the on touched family pick top instance event put sub events if sound = 1 > play sound1, if sound = 2 > play sound2.

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