Thursday, September 13, 2012

Week 4, MOAI threading, easedrivers and callbacks.

Well that was a fun week.  In my infinite wisdom I chose the same Wednesday our prototypes were due to be in charge of the Game Design lecture.  I was going to do this post on Wednesday morning, but decided I should wait and see how the pitches went.  Turns out all I was gonna write about our pitch will fall into the post mortem I'll probably do tomorrow, so lets talk about something else instead.

How about the last big problem I had to overcome with the prototype?  That sounds good to me.  Basically in our game, once the player collected two or more cheese of the same type in a row it triggered this lovely animation of a logo flying off the screen to the right while shrinking.  It was good stuff, but because MOAI objects don't do anything they say they will, if they say they'll do anything at all, when the animation was triggered the game pretty much shit itself and died.  I spent about 2 days tinkering with it trying to figure out what was wrong and pretty much came to the conclusion that spinlocking the thread the animation was running on was also locking the thread that spawned the animation, which was the main game loop.  That kind of defeats the entire reason to ever thread anything ever, but it's the best conclusion I could come up with after receiving a grand total of zero replies from the ever burgeoning and helpful MOAI community.

Anyways, I tried an alternative solution using MOAIeasedrivers, and ran into the lovely problem that the example code I was going off of was using a method whose name had since been changed, but not updated in any convenient and easy to read place, like perhaps the MOAI documentation.  Instead I found a brief blurb in a "Breaking Updates" article on the MOAI wiki page after a few hours of sporadic googling.  (In an effort to save random googlers the same trouble setLength is now setSpan).  To make a long story short, I spent 3 hours implementing a whole new way of doing the animation to achieve the exact same broken results.  Fantastic!

Finally, I reluctantly tried implementing the animation by daisy chaining callback methods together with an event handler.  The very method an official MOAI tutorial warned me against using due to unnecessary complexity that could be avoided with spinlocking threads and easedrivers.

It worked flawlessly and took less than five minutes to implement...  Thanks for the suggestion, Jon.

No comments:

Post a Comment