Straight Forward Touch/Mouse Drag Offset? [Solved]

0 favourites
  • 6 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi there, I was trying to figure out a way to do a drag / offset so when i drag something it doesn't snap to center.

    I found this thread scirra.com/forum/no-offset-drag-and-drop_topic47745.html but following the one available capx, it didn't work when I tried to reproduce it and all the while it struck me as oddly complicated to achieve the desired result.

    Of course the capx out there works great, but when I tried to replicate it, it failed, but it was kinda complicated so I couldn't understand the need for having additional instance variables "mangle"? "mdist"? i don't understand what those names mean related to the offset..

    I see the drag/drop behavior but it doesn't seem to address the idea of mouse offset.

    So yea I just wanted to see if there was some straight forward approach to allow you to touch the lower corner of a dragable object and not have it snap to center but rather let you drag it from where you touch the object.

    Thanks!

    Caleb

  • Off the top of my head...You can try storing the distance between the mouse and the object in private vars when it's clicked (by subtracting both x & y coordinates), then set the object position to the mouse minus those vars every tick. Of course you'd need a "picked" variable to decide if the object should be dragged.

    The pin behavior would come in handy here since it accounts for offset, angle, etc. but I don't think you can pin an object to the cursor, and any object following the cursor lags so it won't be totally accurate.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Instead of using the drag and drop behaviour you could choose to do something like this.

    give the object three instance variables, picked, offsetX, OffsetY

    on object clicked

    • set picked to true
    • set offsetx to object.x-mouse.x
    • set offsety to object.y-mouse.y

    object is picked

    • set object x to mouse.x+object.offsetx
    • set object y to mouse.y+object.offsety

    on mouse button released - object set picked to false

    I'm on mobile, so I can't check the events inside construct atm, but it should be something like this.

  • LittleStain i follow this, but "object is picked". I can't find an action that matches that.

    my attempt failed to result in a proper drag and i imagine the object is picked part is a big piece of it

    dropbox.com/s/ih8hjpukbmzy96f/TD_Test_4.capx

    Thanks!

    Caleb

  • part12studios

    Hey!)

    Here, you forgot to set position of the object to mouse.position + offset)

    PM'd you.

  • awesome thanks JJList and everyone for your input. This is great. I just know that offset/dragging will be something I need to use and this is a much more efficient way to achieve this effect

    Thanks!

    Caleb

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