Looping scene2d Actor actions

Anything libgdx related goes here!

Looping scene2d Actor actions

Postby Chuck » Thu Jul 12, 2012 5:51 am

I have an actor that needs to run a series of actions continuously in a loop. I'm wondering if this tail-recursive idiom is the best way to go about it, or if there's a higher level API that I'm missing out on:

Code: Select all
void animation(Actor a) {
  a.addAction(sequence(
        moveBy(x,y,t),
        delay(d),
        moveTo(x2,t2,t),
        ...
        run(new Runnable() { public void run() { animation(a) }})
   ));
}


Any advice?
Chuck
 
Posts: 5
Joined: Thu Jul 12, 2012 5:38 am

Re: Looping scene2d Actor actions

Postby Varriount » Thu Jul 12, 2012 7:54 pm

Erm, how long is this animation running for? That code works, however it will end up creating a new animation object everytime it loops, which can be a problem if you are trying to deploy to phones or devices with lower amounts of ram.
After looking at the java docs, it does appear as if a looping action exists, here - http://libgdx.badlogicgames.com/nightli ... ction.html
Think of the unanswered posters : search.php?search_id=unanswered
If I'm you and you're me, then who's he?
Varriount
 
Posts: 249
Joined: Tue Jun 05, 2012 2:48 pm

Re: Looping scene2d Actor actions

Postby broken-e » Thu Jul 12, 2012 9:16 pm

There's a RepeatAction that you can set to run forever... I haven't used the new Scene2d package yet so I couldn't say from experience. Previously there was a Forever action if I remember right.

Edit: Varriount already linked to it.
broken-e
 
Posts: 603
Joined: Sun Feb 06, 2011 7:20 am

Re: Looping scene2d Actor actions

Postby Chuck » Thu Jul 12, 2012 10:08 pm

It's running as a desktop application on a fairly beefy machine. I had 10,000 of those loops going full blast for about a half hour and it was still running a smooth 60fps, so it doesn't appear to be a problem, but my concern was forward-looking for Android and its less than stellar gc, yes.

Thanks for the pointer to RepeatAction. Looks like there's a Actions.forever() convenience method I somehow missed the first time around, and it looks like just what I needed.
Chuck
 
Posts: 5
Joined: Thu Jul 12, 2012 5:38 am


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 8 guests