How do I make construct differentiate the same item?

0 favourites
  • 5 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hello guys !

    It's hard to describe in the title, but it's not that hard to understand.

    Take a look at the following image:

    As you can see, i'm trying to use the drag and drop behavior. It's a simple game I'm trying to make: when you move and drop a pawn on another one, it will destroy it and start another animation with a 2 on it (thus implying that you've put your pawn on the other). You can do that with the yellow pawn (Pion_jaune) and the red pawn (Pion_rouge) on any other pawn (which mean I can drop a red pawn on a red or on a yellow one, and a yellow on a red or a yellow one too)

    Whenever I pick one, I register their coordinates in "jx, jy", and then I calculate its distance to the one that gets "dropped on". If it's to far away, the moving pawn gets back to its initial position, and nothing happen. (thus the "else" condition)

    It works perfectly fine when I'm dropping the yellow one on the red one.

    But then, things gets harder...

    When I use the same code for the yellow drop on the yellow, it doesn't work.

    And I know why it does'nt work, it's obviously because construct doesn't make the difference between the one that is dragged and dropped and the one that gets "dropped on". It's also hard for it when I'm calculating the distance, because I don't know which "Pion_jaune.X"/"Pion_jaune.Y" it takes : the one I'm dragging or the one i'm dropping the pawn on?

    So, to sum up everything, I need to tell construct which one is the one that I'm dragging and dropping, and which one I'm dropping my pawn on

    The problem is, there will be a lot of pawn and a lot of global conditions applied to them. I really can't afford to use UID and make conditions on every single ones of them, because I'm going to collapse during the work haha.

    Sorry if I made mistakes, English is not my main langage (I'm French, if you ever wonder )

    Thank you for taking time to help others, it means a lot to me

  • I have not tested it but you may try this:

    Create another object (I'll call it BASE) and make a container with it and your pion, pin it to your pion and on drag and drop start unpin it, then check if your pion is over a BASE object, call a function passing the UID, in the function pick your BASE by UID and you'll have the reference to the pion you are over (because it's a container)

  • You can use instance variables as conditions for picking... for example you can have the one you are dragging with an instance variable that is called IsBeingDragged and use it like a boolean value (on or off - 0 or 1).

    Then you can use this variable as part of your picking comparison (if sprite.variable(IsBeingDragged)=1)

    Likewise you can apply instance variables to the pawns still on the board based on whatever criteria you choose (a positioning number, or a unique count/ID, etc) as the other half of the picking condition.

    As davidochoa mentioned, you can try to use containers for easier picking - just be aware that if you are destorying any object in the container it will also destroy other members of the container. You can set these items to invisible instead of destroying them as an alternative way (this is how I have limb dismemberment working on my container based character model).

    Hope this helps

    *EDIT*

    Looking at your newly included code screen capture, you can also simply try adding a loop "for each yellow" into your event condition in row 34. I think that should work.

    ~Sol

  • Hey guys! Thanks for your answers !

    In the end I couldn't manage to make it work the way you told me(I don't know if I did it badly or if it just doesn't work), but it inspired me to "cheat" a little: I created a "base" and whenever you click a pawn, it destroys itself and spawns the "base" under the click. If dropped on another pawn it will work since it's not the same object, and if it's not placed on another pawn, the base is destroyed and the game spawns a normal pawn where you started the dragging. It works fine, even though there's a lot of destroy/creating haha.

    However, thanks for the fast answers. You guys rules !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes sometimes using a separate object can make like easier. Instance picking can be difficult sometimes, especially when you have a lot of actions going on (like dragging and dropping while colliding - under specific circumstances).

    I would say that 50% of problems people have with using C2 end up being instance picking related - and the other 50% of problems are usually still something to do with instance picking, lol.

    Glad you fixed it though

    ~Sol

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