Wednesday, December 2, 2009

Stardust Movie Clip



Stardust project homepage


If you've played with Stardust for a while, you might notice that there's an Emitter.stepTimeInterval property which allows you to dynamically adjust the particle simulation timescale. Here's one demo showing you the adjustable timescale feature in action.

Now that you can adjust the timescale of particle simulation, the next problem is how to synchronize your movie clips with the timescale.

Originally, there was only a StardustSprite class that extends the Sprite class. My original intent was simple: allow a display object to respond to each Emitter.step() method call and to have access to timescale information, in turn updating itself correspondingly. If a particle's display object is a subclass of the StardustSprite class, and the emitter has a StardustSpriteUpdate action added to it, then the display object's update() method is invoked upon each emitter step, with a reference to the emitter, timescale information, and a reference to the particle's data passed in as parameters.

In order to synchronize movie clips with the dynamically adjusted timescale, I wrote the StardustMovieClip class, which pretty much is just a movie clip version of the StardustSprite class, and I extracted the update() method into a separate interface, the IStardustSprite interface. Now if you use a movie clip that extends the StardustMovieClip class for the particles and add the StardustSpriteUpdate action to the emitter, you can handle timescale change by overriding the update method() in your class. I'll write a base class just for this purpose when I have time. But for now, you can try it yourself if you're interested.

Another addition to the StardustSprite family is the IStardustSprite.init() method. My original intention was to provide a way to "reset" recycled display objects for particles initialized by the PooledDisplayObjectClass. Since used display objects are recycled into a pool and taken out again for future use, they indeed need a way to reset themselves when they are taken out from the pool and used again. For instance, you might want reset the playhead of your movie clips back to the first frame. To invoke the IStardustSprite.init() method, add the StardustSpriteInit initializer to the emitter.

No comments: