Drag and drop(SOLVED)

Tobben2111

  • Posts: 185
Primarily I want to drag and drop 2 different types of actors. Should only be possible to take one actor at the time.

I would also be so honest to say that I do not 100% understand what I have coded so far. Tried to find help through previous forum topic.

I would be very grateful for help and an explanation of the choice of code blocks :)

Atm my codes only drag one actor, last placed blue boom on the scene.


« Last Edit: May 20, 2014, 08:27:20 am by Tobben2111 »

Tuo

  • *
  • Posts: 2469
If you do it as an actor behavior, there's  a lot less headache. Here's the idea I'd use, which uses just three attributes. "Dragging?" is a boolean to see if the mouse was pressed on the actor. "OldX" and "OldY" get the comparison location of the mouse vs. the actor at the start (so if you click in the upper-left corner of the actor, that's where you'll drag it from, etc.). If you don't like that part, you can just always subtract the x-center and y-center of the actor instead so that the mouse is over the middle of the actor (simplifies the code a lot as you can take out all of the OldX/OldY codes). Then, if the mouse was released, reset the "Dragging?" (so that it no longer moves with the mouse).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

Tobben2111

  • Posts: 185
Tyvm again, Tuo :)

I do have one problem, I can still drag two actors at the same time. If I press one of the blue bombe, grab it and then move my mouse over to the other blue bombe(still pressing mouse). I can still drag the other blue bombe. Kinda difficult to see in the picture, but I am grapping both of them.



I can send the game file@PM if it is a bit difficult to see the problem from a screen shot :)

Tuo

  • *
  • Posts: 2469
How exactly do you want the mechanism to work? I'm a bit confused.
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

Tobben2111

  • Posts: 185
Drag and drop one actor at the time. One blue bomb, one green bomb. Almost works, But for some reason, if I press and hold down mouse, grab one blue bomb, keep on pressing and move the mouse over another blue bomb, I grab that up also :S Or if they overlap.

On the picture above, I am grabbing two bombs at the same time.

« Last Edit: May 19, 2014, 10:22:10 pm by Tobben2111 »

Tuo

  • *
  • Posts: 2469
In the last conditional, take out "and dragged = true". That should do it.
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

Tobben2111

  • Posts: 185
Tyvm again, Tuo :)

Code below works as it should for other ppl with the same problem! :) I had some old code blocks in scene behavior which messed up my actor behavior.