Richie Jindal <[EMAIL PROTECTED]>
> Any suggestions as to how i can create a line from the
> midpoint of one sprite to the midpoint of the second
> sprite.

Hi Richie,

To determine the center of a sprite (regardless of its regPoint):

on GetSpriteCenter(aSprite)
  tRect = aSprite.rect
  tCenterH = (tRect.left + tRect.right) / 2
  tCenterV = (tRect.top + tRect.bottom) / 2
  return point(tCenterH, tCenterV)
end


To draw a line from one point to another:

on DrawLine startPoint, endPoint, lineSprite
  startH     = startPoint.locH
  startV     = startPoint.locV
  endH       = endPoint.locH
  endV       = endPoint.locV

  tDirection = (startH - endH) * (startV - endV) < 0
  lineSprite.member.lineDirection = tDirection
  tLeftAdjust  = lineSprite.lineSize / 2
  tRightAdjust = lineSprite.lineSize - tLeftAdjust

  tLeft   = min (startH, endH) - tLeftAdjust
  tRight  = max (startH, endH) + tRightAdjust
  tTop    = min (startV, endV) - tLeftAdjust
  tBottom = max (startV, endV) + tRightAdjust

  lineSprite.rect = rect(tLeft, tTop, tRight, tBottom)
end DrawLine


To test:

1) Create a movie with sprites in channels 1 and 2
2) Draw a Line Shape sprite in channel 3
3) Run the movie
4) Type the following in the Message window:

  tStart = GetSpriteCenter(sprite 1)
  tEnd   = GetSpriteCenter(sprite 2)
  DrawLine(tStart, tEnd, sprite 3)

Cheers,

James


PS: There is a "Draw Connector" behavior in the Library Palette which
may be useful.



[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