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.


Post Reply  Post Thread 
Pages (2): « First [1] 2 Next > Last »
animations in murgalua
Author Message
widged
Junior Member
**


Posts: 35
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
animations in murgalua

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.

05-28-2007 09:16 AM
Visit this user's website Find all posts by this user Quote this message in a reply
widged
Junior Member
**


Posts: 35
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #2
RE: animations in murgalua

Bill (igame3D) provided the solution:

Code:
function animate_callback(object)
      repeat
        Fl:wait(.05);
        coroutine.resume(anim)
        window:redraw();
      until coroutine.status(anim) == "dead"
end


much simpler... now I only need to understand how to get an animation to run each time I press on that play button.

This post was last modified: 05-28-2007 07:34 PM by widged.

05-28-2007 10:28 AM
Visit this user's website Find all posts by this user Quote this message in a reply
widged
Junior Member
**


Posts: 35
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #3
RE: animations in murgalua

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.

05-28-2007 10:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #4
RE: animations in murgalua

This is awesome, I'm glad you found it something you could roll with.
Can't wait to see what happens next...

This post was last modified: 06-05-2007 02:09 PM by iGame3D.

05-28-2007 12:31 PM
Visit this user's website Find all posts by this user Quote this message in a reply
chrimo
Member
***


Posts: 94
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #5
RE: animations in murgalua

Hi,
WOW, cool!
This very interesting example of lua programming answers many of my beginners questions Big Grin

Thanks for more
Bye
Christian

05-29-2007 08:10 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: animations in murgalua

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

05-29-2007 09:52 PM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #7
RE: animations in murgalua

At the bottom of lib/bezier.lua

Code:
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.

05-30-2007 12:08 AM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #8
RE: animations in murgalua

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)



Attached File(s)
.gz File  fish-ani.tar.gz (Size: 5.92 KB / Downloads: 9)
06-23-2007 05:57 PM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #9
RE: animations in murgalua

Ok here's my version. Auto Plays on start.
Space bar starts and stops the animation and you can control the animation speed in the script.



Attached File(s)
.zip File  mikanim.zip (Size: 8.61 KB / Downloads: 7)

This post was last modified: 06-25-2007 10:43 AM by iGame3D.

06-25-2007 10:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #10
RE: animations in murgalua

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

06-25-2007 11:31 AM
Find all posts by this user Quote this message in a reply
Pages (2): « First [1] 2 Next > Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: