Wander Motion Class Update

I just uploaded an update to the Wander motion class I released a couple weeks ago.

This version has some new features that I’ve added as I needed them, like:

  • targetObject: set the Wander to use the x/y of another display object as it’s target x/y. There are lots of possibilities with this: you can follow another wandering sprite, follow a sprite moving in a completely different way (ex. a bouncing ball), or even follow a sprite that was tweened in the timeline or via a tweening library.
  • rotationLimit: sets a limit on the maximum amount that the rotation can change in a single update of the wander. You can use this to get nice smooth arcs and more gradual responses (particularly when using targetObject).
  • update(): you can set autoUpdate (which replaces paused) to false, and call update directly if you have a central tick dispatcher.
  • getShortRotation(): exposed this helper method for general use.
  • always operates on the target’s current rotation. Now you can change the rotation between updates, and Wander will use the new rotation properly.
  • oldRotation: stores previous rotation value.
  • fixed a couple of minor issues.
  • included FLAs for the demos.

Continue reading →

AS3 ProximityManager V2

Mike Chambers recently hosted a contest to write a faster version of my AS3 ProximityManager class (which was a lazy port of my AS2 version). Many of the results were blazing fast, but not really suited to or optimized for real-world use (including my entry, that took 2nd place).

I thought it would be good to release a more optimized version of my library that was designed for real use. This version is significantly slower in Mike’s benchmarks (about 2-3X slower), but that’s because it is tuned for real use cases, concerns itself more with memory use, and includes features like list management, non-zero origins, and variable radii.

It provides a good lesson – optimization is great, but it’s necessity in context always has to be weighed against API, feature, and readability concerns.

Here’s quick demo of it in action, showing 5000 items being updated and compared to the 4 bases every frame:

Continue reading →

Flash Player 10.1 Prerelease on Labs

Adobe just released a beta / prerelease of Flash Player 10.1 on labs. Major improvements include global error handling, out of memory handling, better browser integration, support for browser privacy modes, globalization support, media streaming enhancements, additional content protection options, and a focus on mobile including multitouch.

You can download the FP 10.1 beta player here.

Get all the juicy details in the release notes.

AS3 Kaleidoscope Class

Yesterday, I decided that the outputs from my Wander class would look better with a bit more symmetry, so I spent a couple hours building an AS3 Kaleidoscope class. I thought I’d share the results under the usual MIT license.

It’s fairly fast and robust, supporting one or more slices (not sure why I supported 1 slice, but I did), reflection, display objects or bitmapdata as a source, rotation / position offsets, and a fast mode when using a bitmapdata source without offsets for better performance. I haven’t benchmarked it against PixelBender implementations yet, but plan to do so some time this week.

I’ll post some of the more complex things I’ve been doing with it tomorrow. But here’s the simple demo that’s included with the download:

Continue reading →

Calculating Logarithms With an Arbitrary Base in AS3

If you’ve ever wanted to calculate the logarithm of a number using a base other than Math.E in AS3, you may have noticed the lack of a Math function to do this (ex. Math.logx()). Most likely, if you were doing this, you already knew how to calculate a logarithm with an arbitrary base using the tools you had. But, if you were like me, and knew just enough to know what you wanted, but not enough to know how to get it, this simple function might save you the time it takes to figure it out:

function logx(val:Number, base:Number=10):Number {
return Math.log(val)/Math.log(base)
}

So, “2 log 8” would be logx(8,2).

To be honest, I’m mostly posting this for my own reference when I forget it again in a few months. 🙂

Feel free to correct me if there’s a better way to do this.

Great Pumpkin Showdown ’09 Results

After a week of voting, we’re ready to crown the winners of the 2009 gskinner.com Great Pumpkin Showdown. It was a much closer contest than last year, with the spread between the winners and losers being only about 2:1, but ultimately one pumpkin reigned supreme.

Despite a concerted campaign by certain unnamed third parties to prevent me winning (you know who you are, BWC), my wife Bobi and I took the lead with our pumpkin “Misutaa Supaakoru!” (aka Mr. Sparkle). Go team Skinner!

Thanks to everyone who voted! Here’s a shot of all the pumpkins from this year:

Playing Records (Vinyl) With ActionScript

Rather than just blog an experiment, and leave it at that, I thought I’d blog the story and thought behind the experiment. Hopefully it’s interesting to someone. 🙂

The Idea

Friday morning I woke up with the random idea to try to simulate playing records in Flash. Don’t ask me where it came from, I just remember waking up and saying to my wife “I wonder if I could make MP3s sound like records with ActionScript?”. She smiled and nodded and said it sounded like a lovely idea (she’s used to humoring random thoughts first thing in the morning). If I were to take a guess, I’d guess the idea grew from a seed planted a month or so ago when my wife and I were discussing the idea of getting a new record player. Not sure why it took a month to turn into an idea, but apparently I think slowly.

I headed to the office and started thinking through the code. Beyond a cursory glance, I’ve never really played with any of the new sound APIs, so I managed to justify this experiment to my team as R&D for future projects.

Continue reading →

Wander Motion Class

I recently put together a simple class for managing “wandering” motion in AS3, and thought I would share it. It’s a pretty flexible class, with a lot of different options:

  • specify speed
  • x, y, and rotation targets
  • specify constant trend strength to move towards the target.
  • specify a count and a delayCount to have the trend strength increase over time.
  • outer radius specifies the maximum distance from the x/y target the object can move
  • inner radius specifies when the trend starts (ie. within inner radius, outer radius has no effect)
  • control randomness with varySpeed and varyRotation
  • onChange and onComplete callbacks

Continue reading →