MisterX wrote:

Alex

Here's the new script I made - note that now it's TAOO style ;)
It applies to any control's rect... And it swaps layers at some
point.
The third parameter is a bit improved and the layer switch couldn't
be smarter - no detection needed however it will switch one image's layer above anything else... That can be changed correctly with a bit more scripting...

I've changed this (hopefully improved it) some more, so here it is back to add to your library.

I've made the movement more "natural", and I've added a couple of more parameters to support that.

The objects now accelerate from rest up to a "turnover" point, and then decelerate to a stop.

on imageSwap pObj1, pObj2, pNumber, pTurnover, pTime

pNumber : number of steps to make the move
pTurnover : number of steps of acceleration (remainder are deceleration)
pTime : number of msec between each step (assuming hw can keep up)

for my jigsaw puzzle game, I'll set the turnover at around 3/4 of the total - so the pieces speed up and then screech into place just in time :-)

(note it puts the moving objects on the top layers - up to you whether to do that or swap their layers).

on mouseUp
 imageswap the long name of img 1, the long name of img 2,fld 1
end mouseUp


on imageSwap pObj1, pObj2, pNumber, pTurnover, pTime
   local r1, r2
   local dtlx, dtly, dbrx, dbry
   local tDecc, tRemain
   local tLast
if paramCount() < 3 or pNumber is not a number or pNumber < 3 then
       put 20 into pNumber
   end if
if paramCount() < 4 or pTurnover is not a number or pTurnover > pNumber then
       put pNumber / 2 into pTurnover
   end if
if paramCount() < 5 or pTime is not a number then
       put 72 into pTime
   end if
set the layer of pObj1 to the number of layers on this card + 1
   set the layer of pObj2 to the number of layers on this card + 1
put the rect of pObj1 into r1
   put the rect of pObj2 into r2
-- Accelerate from rest until pTurnover, then decelerate to stop at pNumber -- assume acc = 1, so decc can be calculated
   --   v-turn = acc * turnover =  decc * remaining time
   put (pNumber - pTurnover) into tRemain
   put pTurnover / tRemain into tDecc
-- now calculate distance put 0.5 * pTurnover^2 + pTurnover * tRemain - 0.5 * tDecc * tRemain^2 into tDelta put (item 1 of r2 - item 1 of r1)/tDelta into dtlx
   put (item 2 of r2 - item 2 of r1)/tDelta into dtly
   put (item 3 of r2 - item 3 of r1)/tDelta into dbrx
   put (item 4 of r2 - item 4 of r1)/tDelta into dbry
put 0 into N
   put the millisecs into tLast
   repeat with i = 1 to pNumber
       if i <= pTurnover then
           put 0.5 *  i^2   into N
       else
put 0.5 * pTurnover^2 + pTurnover*(i-pTurnover) - ( 0.5 * tDecc * (pTurnover-i)^2 ) into N
       end if
set the rect of pObj1 to trunc(item 1 of r1 + N*dtlx), trunc(item 2 of r1 + N*dtly), trunc(item 3 of r1 + N*dbrx), trunc(item 4 of r1 + N*dbry) set the rect of pObj2 to trunc(item 1 of r2 - N*dtlx), trunc(item 2 of r2 - N*dtly), trunc(item 3 of r2 - N*dbrx), trunc(item 4 of r2 - N*dbry)
       if the millisecs < tLast + pTime then
           wait (tLast + pTime - the millisecs) milliseconds with messages
           put the millisecs into tLast
       end if
   end repeat
end imageSwap

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.361 / Virus Database: 267.12.5/148 - Release Date: 25/10/2005

_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to