<snip>
>  ...    Everything is great so far. Now the problem, when
> the user clicks on the sprite that he/she want and drags it to the work area
> the sprite is suppose to stay with the mouseLoc. If they move to fast the
> sprite doesn't stay with the mouse but moves parallel with it (offset). Also
> if the mouse is to close to the edge of the stage when he/she does a mouseUp
> then the sprite doesn't take it's rightful place on the stage. When the
> mouseUp occurs the sprite goes to the mouseLoc usually but it is very
> distracting on the mouseDown. I added a enterframe with a stillDown event in
> it but now the sprite really jumps around. I'm not sure if I implemented
<snip>


Hi Rich,

An alternative to using "sprite(pSpriteNum).moveableSprite = 1" is to set
the loc of the sprite via lingo. Here's a behaviour and parent script I've
hacked from a similar behaviour I wrote the other day for a grid game.
Basically, when you click the sprite, the behaviour attaches the 'drag'
behaviour (parent script) to itself that moves the sprite to the mouseLoc.
The drag behaviour gets removed on mouseUp.


----------- Behaviour -----------

property mySprite, myDragScript, ancestor

-- Event Handlers

on mouseDown me
  me.mGrabSprite()
end

on mouseUp me
  me.mDropSprite()
end

on mouseUpOutside me
  me.mDropSprite()
end

on beginSprite me
  mySprite = sprite(me.spriteNum)
  myDragScript = script("SpriteDragger").rawnew()
  ancestor = VOID
end

--- Internal Methods

on mGrabSprite me
  ancestor = myDragScript.new(mySprite)
end

on mDropSprite me
  ancestor = VOID
  -- check where it was dropped, move to nearest best gridloc
  put mySprite & " dropped at " & mySprite.loc
end


-----------"SpriteDragger " (Parent Script) -----------

property mySprite, myOffset

on new me, pSpriteInstance
  mySprite = pSpriteInstance
  myOffset = (the mouseLoc - mySprite.loc)
  return me
end

on prepareFrame me
  mySprite.loc = the mouseLoc - myOffSet
end

-------------------------------------------------------

PS - This approach might appear a little more complicated than necessary
since it uses two scripts - ie. you could make a single behaviour that did
"if IamBeingDragged then doDrag" test every exitframe. However, I think the
approach I've used is a lot more neater (and the project I am working on has
a lot of sprites, and with all of them doing 'if tests' on exit frame,
performance slows down noticeably)


Luke Wigley
Multimedia Director/Producer
Mecca Medialight Pty Ltd

Mecca Medialight:                       Medialight Sound Studio:
111 Moor Street                         1 Bakehouse Lane
Fitzroy, Vic. 3065                      North Fitzroy, Vic. 3068
Tel +613 9416 2033                      Tel +613 9416 2033
Fax +613 9416 2055                      Fax +613 9416 2055

www.medialight.com.au
__________________________________________________________________________



[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to