This might be useful to you:
http://forum.thegamecreators.com/?m=forum_view&t=211243&b=6
Here's an example showing how to drag something using the code from the link above:
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
type DragableCircle_t
x as integer
y as integer
radius as integer
isDragging as boolean
endtype
rem place an object that can be dragged
object as DragableCircle_t
object.x = 200
object.y = 200
object.radius = 20
initMouse()
rem main loop
do
rem make sure to process mouse once every loop
processMouse()
rem object can be picked up when the mouse button is just clicked
if Mouse.posEdge && LEFT_MOUSE_BUTTON
rem only pick up object if mouse is in range
rem pythagoras to the rescue!
if (Mouse.position.x-object.x)^2 + (Mouse.position.y-object.y)^2 < object.radius^2
object.isDragging = 1
endif
endif
rem update position of object being dragged
if object.isDragging
object.x = Mouse.position.x
object.y = Mouse.position.y
endif
rem release object when mouse button is released
if Mouse.negEdge && LEFT_MOUSE_BUTTON
object.isDragging = 0
endif
rem draw object
ink 0xFFFFFFFF, 0
circle object.x, object.y, object.radius
rem refresh screen
sync
rem end of main loop
loop
rem ---------------------------------------------------------------------------
rem Mouse positive & negative edge detection
rem by TheComet
rem ---------------------------------------------------------------------------
rem USAGE
rem ===========
rem call initMouse() before main loop to initialise
rem call processMouse() once every loop (preferably at the beginning)
rem call positionMouse() instead of "position mouse"
rem
rem Access the mouse through the global variable "Mouse" instead of using the
rem built in commands:
rem UDT:
rem Mouse.state - Contains the current state, same as mouseclick()
rem Mouse.posEdge - Contains the positive edge bits of all buttons
rem Mouse.negEdge - Contains the negative edge bits of all buttons
rem Mouse.position - Contains the current location of the mouse:
rem Mouse.position.x, Mouse.posotion.y, Mouse.position.z
rem Mouse.relative - Contains delta values for the relative mouse position:
rem Mouse.relative.x, Mouse.relative.y, Mouse.relative.z
rem
rem Constants:
rem (X)_MOUSE_BUTTON is used for AND conjunctions for decoding the mouse bits
rem e.g. "if Mouse.pos && LEFT_MOUSE_BUTTON then print "left button positive"
rem ---------------------------------------------------------------------------
rem MOTIVATION
rem ============
rem 1) DBP's mousemove() commands can only be called once after every "sync"
rem because they update an internal state. This can cause unwanted behaviour.
rem 2) There is no smart edge detection for mice being used. Instead, people
rem are using flags and other weird things.
rem
rem This small section of code addresses these problems and wraps everything
rem to do with the mouse into a global "Mouse" variable.
rem ---------------------------------------------------------------------------
rem LINKS
rem ============
rem source: http://forum.thegamecreators.com/?m=forum_view&t=211243&b=6
rem explanation: http://forum.thegamecreators.com/?m=forum_view&t=211239&b=1
rem ---------------------------------------------------------------------------
#constant LEFT_MOUSE_BUTTON 0x01
#constant RIGHT_MOUSE_BUTTON 0x02
#constant MIDDLE_MOUSE_BUTTON 0x04
type IntVec3
x as integer
y as integer
z as integer
endtype
type MouseVT
state as integer
posEdge as integer
negEdge as integer
position as IntVec3
relative as IntVec3
endtype
function initMouse()
global Mouse as MouseVT
endfunction
function processMouse()
rem fast positive/negative edge detection
Mouse.posEdge = mouseclick() && (Mouse.state..0x07)
Mouse.negEdge = (mouseclick()..0x07) && Mouse.state
Mouse.state = mouseclick()
rem relative positions
Mouse.relative.x = mousemovex()
Mouse.relative.y = mousemovey()
Mouse.relative.z = mousemovez()
rem absolute positions
Mouse.position.x = mousex()
Mouse.position.y = mousey()
Mouse.position.z = mousez()
endfunction
function positionMouse(x, y)
Mouse.position.x = x
Mouse.position.y = y
position mouse x, y
endfunction
The idea is simple: Every object that can be picked up stores a flag indicating whether it's being dragged or not. When the mouse is clicked, every object that's within range of the mouse will set its flag to "enabled". While the mouse is being held down, position all objects with an enabled flag at the coordinates of the mouse. When the mouse button is released, reset all flags to "disabled".
This method has one drawback: You can drag multiple objects at the same time. If you don't want this behaviour, then instead of giving each object an individual flag, create a global flag that stores the active object being dragged. This way only one object can be picked up at a time.