Posts tagged actionscript
Box2D Flex Complex Shapes Mapping
2One of the drawbacks in box2d is that it’s not supporting concave polygon shapes .
for that box2d flex employs several algorithms and converts a complex shape to a set of polygons (I took the idea from 3d modeling)
at this point i would like to give credits to
- sakri.net for he’s shape outline algorithm
- makc.coverthesky.com for he’s polygon2d
both state that their algorithms are far from perfect but for a v0.2 it’s a good start.
in this case I’ll start from the demo and then go into the code so see how the doll bellow is segmented to several triangles.
first thing is to understand how what the doll constructs of , in our case it’s a graphics
our object can be comprised of anything , graphic shapes , ui controls, images etc’ it has only one caveat - It’s edges must be transparent .
The next thing it to take a look at our physics container
you can see that autoStartPhysicsEngine is set to false. By default SkinnablePhysicsContainer maps all it’s flex objects to box2d shapes on creation, this time we want to interfere before hand and give the engine a different directive to try and map the shape not by it’s boundingBox but by it’s actual edges.
This is done by actionscript code, in which we tell our physics container to parse complex shape and pass it with the shape id and a parsing object, afterwards we call the physics engine to start.
you can see the the shape parser receives an argument specifying the quality of it’s mapping , this is done for performance improvement but might impair edges fidelity.
Flex 3 label RTL support
1If you know or not , I’m leaving and working in Israel, where we have the most annoying text rendering issues.
we write in right to left order – that means in the opposite direction of most languages. Letters and words are left to right, though numbers and other symbols remain right to left.
Through the years I’ve seen (and even wrote) noumerous attempts to build an AS class that will provide this functionality to flash, all of them suffered from quirks and different edge cases.
About a year a go Adobe published a new text rendering engine (TLF) which wasn’t integrated into Flex3 framework , and though flex4 includes the new TLF some still need to work with the 3.x framework so here is a simple example of implementing true RTL label in flex 3 note that you need to download and install Text Layout Framework on your development machine in order to compile the code.