Animation technique finally

Posted by Chris Fri, 08 Feb 2008 19:36:00 GMT

I ended up taking a slightly different approach to my animation last night. It basically consists of a couple different parts.

The first part was modifying the PositionableItem class to contain a few more pieces of information:

  1. Target Position (publicly settable)
  2. Original Position (internal, set as a copy of the current position when the Target Position is set)

Then I added a step(percent) method that calculates a new position based on the current position, the original position, the target position and the percent specified.

After that, my animation logic consists of setting target positions, and then looping for a specified time. During each loop the step(percent) method is called on each object and then each object is drawn. I already had code in place to draw an image based on it’s position information, so it was pretty easy.

I loop for 250ms, sleeping for 5ms after each loop, which keeps my CPU usage low.

It works great. :)

Comments

Leave a comment

Comments