mouse within oval filled area

Mike Bonner bonnmike at gmail.com
Sun Nov 13 10:43:39 EST 2011


Just tried doing the detection using AE5 and it works like a champ.

With the collisionListernerDemo, a couple really simple changes gets the
job done.

in the card script I added the following:

####
command startMove
   if tMoving is empty then put false into tMoving
   --put false into tMoving
   put not tMoving into tMoving
   mover
end startMove

command mover
   if tMoving then
      lock screen
      set the loc of grc "grmypnt" to the mouseloc
      unlock screen
      send mover to me in 10 milliseconds
   end if
end mover
####

In the button script that starts the demo listening I added a startmove
call so the final handler ends up as so:

####
--> all handlers

on mouseUp pMouseBtnNo
   if "animationEngine" is not among the lines of the stacksInUse then
      answer "This stack needs animationEngine 5 or higher to run."
      exit mouseUp
   end if
   aeStopListeningForCollisions
   local tList
   set the flag of me to not the flag of me
   if the flag of me then
      -- set up graphics to be draggable
      repeat with i=1 to the number of graphics
         set the constrainRectangular of graphic i to the rect of this cd
         -- graphics need to be opaque to be draggable
         set the opaque of graphic i to true
      end repeat
      repeat with i = 2 to the number of graphics
         --put the long id of graphic i &",bounds"& cr after tList
         put the long id of graphic i & cr after tList
      end repeat
      -- remove trailing carriage return
      delete char -1 of tList
      set the aeListenForCollisionsWith of graphic 1 to tList
      -- right now we assume all but graphic 1 are predators
      -- you could set up lists for each graphic though
      aeStartListeningForCollisions
      set the label of me to "Stop listening for collisions"
   else
      aeStopListeningForCollisions
      set the label of me to "Start listening for collisions"
   end if
   startMove -- my change
end mouseUp
####

I then created a grc named grmypnt and moved its layer to the back so that
it becomes the focus of the listener. It also needs to be moved to the back
so you can still click other items. (otherwise you're clicking the graphic
no matter WHERE the mouse is.

On moving the mouse around and over the other graphics, the output field
populates with the other graphics that are being mouseovered. Seems to work
pretty well.



More information about the use-livecode mailing list