Cool Script animation
xbury.cs at clearstream.com
xbury.cs at clearstream.com
Fri Feb 18 09:46:17 EST 2005
Hi everyone,
I made this cool conversion of the script Bit-101.com proposes for
tutorials.
check it out...
http://www.bit-101.com/tutorials/gravity.html
It's not so obvious converting flash scripts and their convoluted
animation
frames but I got it down to something simple and easy now. And there's
more to come!
The only thing that really got me troubled however is that if I put in a
pass mousedown
in the end of the mousedown script (see commented line in script below and
its preceding line
which is supposed to be called by the mouseup), the mouseup handler is not
called at all!
So I mousedown, pass mousedown and there's no mouseup!
I made a test button and it did work. So, why didn't it work here as
expected? The Idle?
Wouldn't that be the logical event queue?
See the script below...
To make it work,
create a stack
create graphic
set the style of it to oval
set the script of it to the scriptbelow
cheers
Xavier
<script>
local xspeed, yspeed
local oldx, oldy
local rightedge,leftedge
local topedge, bottomedge
local gravity, fxdrag, bounce
local dragging
local inited
on mousedown
local mouseHoffset, mousevoffset
if inited is not true then
initme
end if
put true into dragging
put the mouseh - the left of me into mouseHoffset
put the mousev - the top of me into mouseVoffset
repeat while the mouse is down
set the topleft of me to the mouseh - mousehoffset,the mousev -
mousevoffset
domove 1
end repeat
put false into dragging -- this is in so the script works
--pass mousedown
end mousedown
on mouseup
put false into dragging
domove 1
end mouseup
on initme
put the left of graphic 1 into oldx
put the top of graphic 1 into oldy
put random(60)-30 into xspeed
put random(60)-30 into yspeed
put 0 into leftedge
put 0 into topedge
put width of this cd into rightedge
put the height of this cd into bottomedge
put 2 into gravity
put 0.98 into fxdrag
put 0.9 into bounce
put true into inited
domove 1
end initme
on idle
domove 1
end idle
on domove objnum
local x, y
if not dragging then
put the left of graphic objnum into x
add xspeed to x
set the left of graphic objnum to x
if (x + the width of graphic objnum / 2 > rightedge) then
put rightedge-the width of graphic objnum / 2 into x
set the left of graphic objnum to x
put -xspeed * bounce into xspeed
end if
if (the left of graphic objnum - the width of graphic objnum / 2 <
leftedge) then
set the left of graphic objnum to leftedge + the width of graphic
objnum / 2
put -xspeed*bounce into xspeed
end if
put the top of graphic objnum into y
add yspeed to y
set the top of graphic objnum to y
if (the top of graphic objnum + the height of graphic objnum / 2 >
bottomedge) then
set the top of graphic objnum to bottomedge - the height of graphic
objnum / 2
put -yspeed * bounce into yspeed
end if
if (the top of graphic objnum - the height of graphic objnum / 2 <
topedge) then
set the top of graphic objnum to topedge + the height of graphic
objnum / 2
put -yspeed * bounce into yspeed
end if
put yspeed * fxdrag + gravity into yspeed
put xspeed * fxdrag into xspeed
else
put objnum, oldx
put the left of graphic objnum - oldx into xspeed
put the top of graphic objnum - oldy into yspeed
put the left of graphic objnum into oldx
put the top of graphic objnum into oldy
end if
end domove
-----------------------------------------
Visit us at http://www.clearstream.com
IMPORTANT MESSAGE Internet communications are not secure and therefore
Clearstream International does not accept legal responsibility for the
contents of this message. The information contained in this e-mail is
confidential and may be legally privileged. It is intended solely for the
addressee. If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance on it,
is prohibited and may be unlawful. Any views expressed in this e-mail are
those of the individual sender, except where the sender specifically states
them to be the views of Clearstream International or of any of its
affiliates or subsidiaries. END OF DISCLAIMER
More information about the use-livecode
mailing list