Drag and drop...

JlmCJlmC Member Posts: 129
edited November -1 in Working with GS (Mac)
Hello

How can i make my Actor to drag and object while im touching the screen, then, when i release the screen, my actor release the object.

thanks

Comments

  • cbtcbt Member Posts: 644
    Lets say u have 2 actors, actor1, actor2, both 100x100px in size.

    Create 2 real attributes X and Y.

    On actor 1;
    Constrain game.X to self.X
    Constrain game.Y to self.Y
    ---
    When touch is pressed;
    Constrain self.X to touch1.X
    Constrain self.Y to touch1.Y

    On actor 2;
    When mouse button is down;
    Constrain self.X to game.X+100
    Constrain self.Y to game.Y

    That should do it..
  • cbtcbt Member Posts: 644
    I think he asked about, one actor to drag another.

    And on my 1st post it should be;

    n actor 2;
    When mouse button is down and overlaps or collides with actor1;
    Constrain self.X to game.X+100
    Constrain self.Y to game.Y
  • JlmCJlmC Member Posts: 129
    How can i make this using a third actor like a Button?

    Nah, nevermind, i got it.

    Thank you very much
  • Metronome49Metronome49 Member Posts: 297
    Hey @Booth, et al... In your example here, what I am missing is what part of the logic tells the Actor to constrain to the mouse x & y when touch is pressed AND THE TOUCH IS ON THE ACTOR.

    I set up something very similar to this, only with mouse-down instead of touch-pressed at first, and I thought it worked, until I clicked outside of the Actor, and I realized a click anywhere on screen causes the Actor to jump to mouse position.

    I have since started testing with touch-inside, and it seems to be working the way I expect, but I can't tell why your example works. Is it the difference between mouse and touch?

    Also, as if that wasn't enough to ask, how does your example scale to if I had several actors with the same functionality on screen, and I wanted Multitouch to be able to arrange them separately?
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Metronome49 said:
    Hey @Booth, et al... In your example here, what I am missing is what part of the logic tells the Actor to constrain to the mouse x & y when touch is pressed AND THE TOUCH IS ON THE ACTOR.

    I set up something very similar to this, only with mouse-down instead of touch-pressed at first, and I thought it worked, until I clicked outside of the Actor, and I realized a click anywhere on screen causes the Actor to jump to mouse position.

    I have since started testing with touch-inside, and it seems to be working the way I expect, but I can't tell why your example works. Is it the difference between mouse and touch?

    Also, as if that wasn't enough to ask, how does your example scale to if I had several actors with the same functionality on screen, and I wanted Multitouch to be able to arrange them separately?

    Touch inside will cause you some issues cause if you move your finger faster than the device can keep up then you'll lose your actor.

    You want touch is pressed and then mouse x and y because mouse x and y give a single touch point instead of figuring out which touch you are dragging with and pressed will keep the rules to follow your touch going even if you slide of the actor.

    Now if you get into multiple actors at the same times needing to be drug around by different touches you will use all the same rules and then add in some multi touch rule like in the joystick demo so it knows which touch to follow.

    Hope that somewhat answers your question

    Aaron

    ___________________________________________________________________________________
    Project Help from Tenrdrmer Click Here

    GS BubbleBall Template HERE!!
    Stacks Level Selection Template HERE!!
    Expanding Option Menu Template HERE!!
    Tenrdrmer's Menu # 3 HERE!!
    Menu #4 - Level Banners HERE!!
    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • Metronome49Metronome49 Member Posts: 297
    @tenrdrmer

    Yeah, that's great advice. Thanks!

    I guess what I'm left wondering is, with Booth's instruction above, should I be able to use mouse-down instead of touch-pressed? Or would that give me the results I had before, where even clicking where the actor isn't makes the actor constrain? Is that just an inherent difference between mouse and touch?
  • Metronome49Metronome49 Member Posts: 297
    Okay, nevermind I figured out the above question in the wiki, sorry.
Sign In or Register to comment.