Psyked *
it’s easy once you know how.A more advanced StarRequests, Simple-Box2D & Flickr example.
Posted by James - 01/07/10 at 09:07:28 amJust a little demo I’ve been working on, following my previous post: http://www.psyked.co.uk/actionscript/starrequests-simple-box2d-flickr-mashup-sample.htm. I’ve basically updated the code a little and swapped out the rectangular Box2D objects for star-shaped Box2D objects, and the code is available on GitHub: http://github.com/psyked/StarRequests-Examples/tree/master/Box2d-Flickr-Shapes/
Simple Box2D – Better, cleverer, more optimised.
Posted by James - 03/02/10 at 09:02:44 am
^ This time, that’s an image – saves on the page rendering time!
Another update on the Box2D classes I’m working on. No new features, but some pretty cool expansions and improvements to the library object creation.
If you check out the previous post, you’ll see that the the dynamically drawn shapes weren’t exactly perfect; nor were they very efficient. Oh they worked fine, and traced the detail of the shape very well – but it took a decent chunk of system resources to animate and ended up with some overlaid shapes; which all made the Box2D a bit sluggish and the behaviours buggy.
Continue reading Simple Box2D – Better, cleverer, more optimised….
Demo & Source: Simple Box2D, with curved edges!
Posted by James - 14/01/10 at 12:01:35 am
(The image above this text is actually the Flash movie, if you hadn’t guessed. Try using your mouse to interact. If it’s blank, then something’s gone wrong!)
I’ve been busy working on my Box2D classes again. (As before here and here.) I’m not quite ready to go through the code with some tutorials yet, but you can download the source for this demo here. This version has had a bit more of a proper code cleanup – I’ve un-hacked some hacks I did earlier in development, and added a few more utility functions, but most importantly this version supports SWF library asset importing of multiple shapes, and shapes with curved edges (which it couldn’t do previously).
I feel like I should put that in bold or something, because it’s probably my most-clever bit of code to date. I’m going to settle for saying it twice though: You can import library objects with multiple shapes, and shapes with curved and straight edges. Have a look at the screenshot below and compare it with the Box2D display;
In Flash IDE:
In Box2D:
You can download the source for this demo here.
I’m going to get this as a project on some publicly-available source repository soon. I’d love to hear feedback on it now though!
Simple Box2D – Custom Polygon creation.
Posted by James - 11/01/10 at 09:01:33 amI’ve been working on some classes to simplify Box2D for Actionscript developers (See previous post for a quick intro). The latest update to these classes introduces couple of minor ideas, and one gosh-darned awesome idea, if I do say so myself. Let’s start with the awesome things, and move on from there…
Awesome thing: Creating Custom Polygons
Or rather the methods for creating them. Shapes in Box2D come in three basic flavours – circle, rectangle and custom polygon. Moreover, everything must be convex (no inny bits), have no more than 8 sides, and can’t have holes. On the plus side you can still make larger, more complex objects out of smaller ones – but it all involves a lot of thinking.
So, here’s the solution – or rather, the options.
Polygon creation option #1 – Creating a polygon from an array of points.
Using some clever triangulation code from Splashdust.net, there’s a simple method for creating any custom shape from an array of Point objects. With this method you can create a shape with any number of sides, and not worry about whether the shape is concave or convex. It’ll still break if the edges of your shape interest each other, and doesn’t support holes in the objects you’re creating, but it’s a start.
var array:Array = [ new Point( 0, 0 ), new Point( 10, 0 ), new Point( 10, 10 ), new Point( 20, 10 ), new Point( 20, 0 ), new Point( 30, 0 ), new Point( 30, 30 ), new Point( 0, 30 ) ]; world.createComplexPolygon( 50, 50, array );
Polygon creation option #2 – Creating a polygon from a shape in a library.
This is where things get cool. Creating a shape from a series of points is all well and good, but it’s a laborious process to set up and modify. You can create a shape in the Flash IDE, add your symbol to your library and import it to Box2D. Currently this method only supports single shapes on a single layer, and only straight edges – but multiple shapes, layers and curved edges are definitely on the list for the future.
world.createPolyFromLibraryShape( 300, 100, "sampleShape", "vectorassets.swf" );
Continue reading Simple Box2D – Custom Polygon creation….





