News : The level of daily SPAM has reached insane proportions, all registrations are now manual.
I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.
Having a go at this. Read the Lua 5.0 manual.. nice language! Problem is this is my first lua program. What I tried to do was rewrite a nice little script to move a sprite along a bezier line I wrote with another language.
As I don't know how to make a drag and drop, I use dials to specify the position of the two orange points that makes the extremities of a bezier curve and two green points to define the position of the control handles. This part works nicely.
What I can't figure out how to manage is the animation business. I defined the part of the script that will move the sprite as a coroutine and I resume that coroutine when the user press on the play button. This works when I force an onscreen event to occur (having a message box display a message). This doesn't work anymore when I remove it.
That's the relevant part of script:
Code:
function animate_callback(object)
starttime = os.time()
repeat
curtime = os.time()
delay = curtime - starttime
if delay >= 1 then
coroutine.resume(anim)
fltk.fl_message(delay) --> doesn't work if I remove this
window:redraw();
starttime = curtime
end
until coroutine.status(anim) == "dead"
-- io.output("bezier_points.txt")
-- io.write(serialize(points))
end
The full script is available at: animation script
(as the script refers to lib files and pictures with a path relative to the anim.lua script, it needs to be run from within the folder itself)
Is this a Lua issue?
This post was last modified: 05-28-2007 10:07 AM by widged.
Okay, I don't need the coroutine business anymore. I only need a call
Code:
run_anim(sprite,points)
and a function
Code:
function run_animate(sprite,points)
local pos = {}
for p = 1,100 do
pos = points[p]
Fl:wait(.05);
sprite:position(pos.x,pos.y)
window:redraw();
end
end
New version of the script: animation script
(run anim.lua from within the folder that contains that file)
And for the fun of it, the script in action, captured in a screencast
(quicktime movie recorded on a mac, may not show properly on a pc or linux machine -- the animation is a *lot* smoother than on this movie)
This post was last modified: 05-28-2007 07:35 PM by widged.
This is a groovy test. I'm wondering if I'm seeing it the way it's supposed to be, though. Rather than gradually moving across the window as I expected, the car appears to leap very quickly between a pair of points. It seems to be animated in the sense that I can see the car very briefly at a middle point, but the movement is so quick I'm not sure if it isn't just an optical illusion or if the car is being redrawn as quickly as possible (no wait) at each point along the curve.
Using murgaLua 0.4.1 on Slackware and Damn Small Linux
function run_anim(srpite,points)
local pos = {}
for p = 1,100 do -- should loop for the number of entries in points
pos = points[p]
Fl:wait(.004);
sprite:position(pos.x,pos.y)
window:redraw();
end
end
Should be some kind of speed adjuster around Fl:wait(.004);
On my iMac this is very smooth and Marielle has the same iMac specs mostly.
I replaced with Fl:check();
and it remained smooth so Fl;wait isn't even necessary in there
This works smooth here.
Code:
function run_anim(srpite,points)
local pos = {}
for p = 1,100 do -- should loop for the number of entries in points, set to 10 for testing purposes
pos = points[p]
sprite:position(pos.x,pos.y)
Fl:check();
window:redraw();
end
end
THIS LOOPS BACK AND FORTH
Code:
function run_anim(sprite,points)
local pos = {}
local cnt=1
local loopMod=1
--- LoopBackAndForth
while cnt < 101 do
pos = points[cnt]
sprite:position(pos.x,pos.y)
Fl:check();
window:redraw();
--- rebound looping
if cnt==100 then mSpeed =-1
elseif cnt==1 then mSpeed =1
end
--- move the counter
cnt=cnt+mSpeed
end
end
This post was last modified: 06-05-2007 02:10 PM by iGame3D.
Attached is an animated image sequence demo.
It uses a repeat button as a cheat for an actual loop, which I guess should not be needed with murgaLua 0.5
From John's recent drawing tests it seems like it could be done in 0.4.1, but I don't quite understand how =o)
That's pretty cool. I definitely have to look into that autoplay.
Unfortunately it will need some tweaks to work on my system.
The animation doesn't "animate", in that there is usually a set number of frames per second in an animation but this one tore through the frames so violently that it skipped most of them, my cpu went crazy, and my desktop froze =o)
I wonder if this is a similar issue to the one I had with the cars