Hi leon and alan-

Hope you don't mind my butting in...
That's a nice little script. However, it has a flaw; positioning the
cursor over the center of the rotating sprite produces a "cannot divide
by zero" error. One way of amending this is to add a single line:

  if x2-x1 = 0 then exit

so the entire script reads:

on exitFrame me
  -- get the mouse location
  p = the mouseLoc
  x1 = p.locH
  y1 = p.locV
  
  -- get the sprite location
  x2 = (sprite me.spriteNum).locH
  y2 = (sprite me. spriteNum). locV

  --avoid "cannot divide by zero" error
  if x2-x1 = 0 then exit
  
  -- use atan to compute the angle
  angle = atan(float(y2-y1)/float(x2-x1))
  
  -- correct the angle
  if x1 < x2 then angle = pi()+angle
  
  -- convert the angle to degrees
  angle = angle*360.0/(2.0*pi())
  
  -- set sprite rotation
  (sprite me.spriteNum).rotation = angle + 90
end

regards,
Clars

----------------------------
Alan Andrews wrote:
> Hi leon..
> I found this the other day...
<snip>
> I think this may be what you are looking for...
> regards
> Alan
<snip>

[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