> How are you? fine? ok.
Not really, but thanks for asking
> I want to move a sprite on stage with Lingo. How?
One way is to create a behaviour on the sprite you want to move. This
behaviour sits there waiting for the command to move. When it gets that
command, it adds another behaviour to itself which actually moves the
sprite. Something like this
--------------------------------------------------------------------------
-- Sprite Behaviour to receive the #mMoveTo command
--------------------------------------------------------------------------
property mySprite, myMoverScript, mySavedLoc, ancestor
on beginSprite me
mySprite = sprite(me.spriteNum)
myMoverScript = script("SpriteMover").rawnew()
mySavedLoc = mySprite.loc
ancestor = VOID
end
on mMoveTo me, pEndPoint, pTime
-- pTime is the milliseconds allowed for the move
mySavedLoc = mySprite.loc
ancestor = myMoverScript.new(mySprite, #mAncestorCallBack, mySavedLoc,
pEndPoint, pTime)
end
on mAbortMove me, pReset
ancestor = VOID
if pReset then mySprite.loc = mySavedLoc
end
on mAncestorCallBack me
ancestor = VOID
end
--------------------------------------------------------------------------
-- "SpriteMover" script that gets instantiated to actually move the sprite
--------------------------------------------------------------------------
property mySprite, mySpriteCallBack
property myStartPoint, myEndPoint, myVector
property myTimeAllowed, myStartTime
on new me, pSpriteInstance, pCallBack, pStartPoint, pEndPoint, pTime
mySprite = pSpriteInstance
mySpriteCallBack = pCallBack
myStartPoint = pStartPoint
myEndPoint = pEndPoint
myVector = pEndPoint - pStartPoint
myTimeAllowed = pTime
myStartTime = the milliseconds
return me
end
on prepareFrame me
lapsedRatio = float(the milliseconds - myStartTime) / myTimeAllowed
if abs(lapsedRatio) < 1 then
mySprite.loc = myStartPoint + (lapsedRatio*myVector)
else
mySprite.loc = myEndPoint
call(mySpriteCallBack, mySprite)
end if
end
--------------------------------------------------------------------------
To trigger the move script, you'd have a handler like this somewhere
on mouseDown
-- move the sprite to the point clicked
sendAllSprites(#mMoveTo, the mouseLoc, 2000)
end
Note - these scripts do not use repeat loops, so they will be slower than if
you moved the sprite inside a repeat loop. However, by not using repeat
loops, the behaviour is a much better digital citizen since it will not try
and monopolise the cpu. Also, because its doing the moving on exitframe, the
higher the frame rate the smoother the animation (the animation is time
based, so it will always take the same amount of time to go from point A to
point B. If the frame rate is 999 fps, then it will move smoothly but still
take the same time to get there as if the frame rate is 10).
--
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!]