lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 01/02/2013 18:33, Peter Slížik wrote:

I have quite a hard time imagining a concrete implementation. Is somebody on this list familiar with this topic enough to give a few pointers, book references, or an example maybe?


I have rewritten LÖVE 2D's run loop to use coroutines for animation. There's a scheduler that has non busy timers (i.e. sleeping coroutines are resumed only when it's time for them to wake up.)

One problem with this approach is when you have to draw things on the screen. If you draw inside the coroutines, the order that the drawables are blitted change because of how the scheduler works. I've implemented a simple sprite module so that you can specify a sprite priority. I've rewritten the passing clouds demo and things work just fine.

Another problem I'm facing is to change an object's state. Say you have a rabbit running using a coroutine. This is implemented with a for loop. But then a carrot appears, the rabbit should run to get it. You'd have to check for this state change inside the for loop and act accordingly, so things can get complicated when you take all states in consideration. I'm thinking in implementing a state machine for each game object where each state would be a coroutine, so if the state changes, you just start (or resume) another coroutine for that object.

All this is WIP, but if you want to take a look at the source code ping me and I'll send it to you.

Cheers,

Andre