how to un-grab collided field-objects

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

Post Reply
niconiko
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 32
Joined: Mon Jul 17, 2006 2:28 am
Location: Motegi, Japan

how to un-grab collided field-objects

Post by niconiko » Tue Jun 01, 2010 4:26 am

Hi.

Within a rectangle graphic are several grabbable text-fields. The grabbing action has two constraints:

(1) text-fields cannot be dragged outside the rectangle
(2) text-fields cannot be dragged into each other

For (1), I'm using " set the constrainRectangular". No problem.

For (2), I'm using "intersectrect" within "constrainRectangularCallback" to check for collision. This too is no problem.

The problem is how to release the grabbed text-field when it has collided, i.e., when "intersectrect" returns not-false.

Hope that makes sense.

--
Nicolas Cueto

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: how to un-grab collided field-objects

Post by malte » Tue Jun 01, 2010 4:12 pm

Makes sense. :-)

can you post your callback handler?

Cheers,

malte

niconiko
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 32
Joined: Mon Jul 17, 2006 2:28 am
Location: Motegi, Japan

Re: how to un-grab collided field-objects

Post by niconiko » Thu Jun 03, 2010 1:12 am

Hi Malte,
can you post your callback handler?
Sure can:

Code: Select all

on constrainRectangularExit
   set the cpStartLoc of me to empty
end constrainRectangularExit



on constrainRectangularCallback

   if the cpStartLoc of me is empty then \
         set the cpStartLoc of me to the loc of me
    
   put the loc of me into tGrabbedLoc
   put the rect of me into tGrabbedRect
   put the objects of this card into tObjects
   filter tObjects with "*pasted object*"
   filter tObjects without (the name of me)
   repeat for each line tObject in tObjects
      put word 2 of tObject into tObjectId
      replace quote with "" in tObjectId
      if intersectrect(tGrabbedRect,the rect of field tObjectID) <> "false" then
         ## R E L E A S E   T H E    G R A B  !
         set the loc of me to the cpStartLoc of me
         exit repeat
      end if
   end repeat
   
end constrainRectangularCallback
Thanks.

--
Nicolas Cueto

Post Reply

Return to “Animation Engine”