Posted: 25th Nov 2011 17:25
Anybody got some minimalist drag and drop code? Can't spot any in the examples.
Posted: 25th Nov 2011 21:04
You might want to be more specific...

What type or for what purpose...

Just saying...
Posted: 25th Nov 2011 23:35
Fair enough!

Drag the word "head" onto a picture which has the head defined as a target zone. Dropping on the arm is wrong.
Posted: 26th Nov 2011 21:11
You can detect whether a sprite is under the pointer and whether the pointer is being pressed. Also you can detect where the pointer is on the screen. Using this information is not a big step after that:
+ Code Snippet
if getPointerPressed()=1
    hit = getSpriteHitTest(spr, getPointerX(), getPointerY())
    if hit>0
        rem sprite picked up
        picked = spr
        pX = getPointerX()
        pY = getPointerY()
    endif
else
    if picked>0
        if getPointerState()>0
            rem Sprite being dragged
            cX = getPointerX()
            cY = getPointerY()
            setSpritePosition(picked,getSpriteX()+cX-pX,getSpriteY()+cY-pY)
            pX = cX
            pY = cY
        else
            rem Sprite Dropped
            picked=0
        endif
    endif
endif


Of course if you want to check whether the drop off point is valid that's extra code!
Posted: 27th Nov 2011 0:19
Thanks baxslash. DIY drag-drop then!
Posted: 28th Nov 2011 9:12
Yes, but as with most things it gives you more flexibility in how your controls work.
Posted: 16th Dec 2011 17:48
Thnx baxslash,

the technique works great, using it in my upcoming game.

Thnx
Posted: 16th Dec 2011 19:09
Glad to help!