Archive for November, 2011
A common issue I have while creating Flash/ActionScript 3 games is needing to depth sort DisplayObjects based on some property of the display object itself (most often, their y coordinate). I do this so often that, a while back, I created a special class that extends Sprite and automatically handles this for you. I thought it was finally time to share this handy utility class with the world, so here it is.
For an example, check out the Kung Fu Panda Tales of Po game I worked on. When the characters pass by each other across the “y” plane, they are automatically depth sorted without any extra coding work on my part.
var mcContainer:SpriteAutoSorter = new SpriteAutoSorter(); mcContainer.sPropertyToSortOn = "y"; // "y" is actually used by default so this line is not necessary mcContainer.beginSorting();
And that’s it! Now just addChild and removeChild like normal and everything will be handled for you. To save on performance, you should call stopSorting() when it is no longer required. Enjoy!
At Seven2, I served as the lead developer on the pilot game for a brand new Nickelodeon tv series based on Kung Fu Panda! This recently released game, called called Tales of Po, is in the running to be Nickelodeon’s 2011 Game of the Year (along with Voltron Ultimate Victory, another game that I served as lead dev on)! It’s a side-scrolling rpg-brawler with similarities to Double Dragon, Castle Crashers, etc. Stay tuned for future posts on some of they key development issues & solutions encountered while developing this game. In the mean time, go play it!