Worked like a charm 🙂 Thanks! Again, this is great. I tried Box2D before but I was annoyed that it was all code based and I couldn't place stuff on the stage for fast and easy testing, this is genius!
I made some first steps with this tonight 😀
Flash Builder AS3 Project:
Main extends WCK
Go to the build path settings and add src/Box2DAS3 as a SWC folder, also add src/ to your build path as i created a fla there.
Under src/ folder create a new assets.fla and make sure its publish settings export a SWC. In this case both assets.swc and Box2D.swc will be available in Flex. Not including the Box2D.swc was why i was getting CLIB errors at compile time.
Flash CS4 Project:
Inside assets.fla create a new MovieClip called TestWorld which a class name of TestWorld whose base class is wck.World. I also dragged over a few other items from the test bed. Box20 and Circle20.
I dragged these items into the TestWorld and used the component inspector to set properties. I also gave important objects instance names such as leftWheel.
Then i publish the swf to generate assets.swc which will be picked up by Flash Builder (project > Clean to make sure).
Back in Flash Builder you can call your world up:
var world:World = new TestWorld()
world.x = stage.stageWidth/2;
world.y = stage.stageHeight/2;
addChild(world)
And it runs fine!.
The next thing i tried to do was add a spring joint and i before i got that far, i had an issue with the ConnectorSpring when specified inside the component inspector. Flex didnt seem to like that, also i cant remember well, but flex didnt like WorldClickAdd either. Something about getDefinitionByName is throwing null references but this is no doubt some issue on my behalf.
As a side note, world.leftWheel returns a Circle20 which i have cast as a Sprite which is probably wrong. This is cool however because i can just use the API in flash to draw lines using the Circle20 co-ordinates instead of using the ConnectorSpring movieclip.
The alarm bell was ringing though because i dont know how to reference the actual box2d object. If Circle20 is a DisplayObject (im not even sure what) then where is all the m_properties for that object?
I think this is my final hurdle because if i can access the box2d side then i can continue on like i was only using flash for layout. I have no idea if i am approaching this correctly however.
Anyways ill keep sticking with it and see what i can do, any advice would be great, though no rush.
Cheers.
Thanks Mayo your a Gentleman!
Yeah about getDefinitionByName, it was strange because i added ConnectorSpring to the library with a class name of ConnectorSpring but still got the reference error dispite it being available directly via the SWC. var cs:ConnectorSpring = new ConnectorSpring() but getDefinitionByName("ConnectorSpring") throws me a runtime.
It really does not matter though in the slightest and is merely a error on my behalf no doubt.
Thanks for clearing up the b2Body references.
I might have a go at writing up how to kick things off from a Flex perspective and not from the Flash perspective. I know the Testbed uses the Alchemy port but to benefit from WCK via Flex is a really good thing.
Sorry to ask here but couldn't find information in other places...
I downloaded the code and tried to open... pretty much everything. Nothing worked on my computer, from swf to fla and swc. Nothing worked. I'm guessing this is for CS4?
Is there any documentation about how to implement this port as a substitute for Box2DFlash? Or any documentation I might have missed, because I really can't find anything besides the download of the source.
Thanks in advance.
Mayo:
You've miscounted the cost of conversion. If the api uses V2 consistently, and internally you use b2Vec2, that means every getter must constructing a new vector each time, which will badly hurt garbage collection. The alternative of using b2Vec everywhere is impossible, users cannot cope with destroying vectors manually.
I've got a better suggestion for vectors: Double up the interface with accessors for both.
So, e.g. in b2Body
public function get linearVelocity():b2Vec2Ref
{
return m_linearVelocity;
}
public function GetLinearVelocity():b2Vec2
{
return m_linearVelocity.ToVec2();
}
where I've given the object names that are more consistent (with my own code, that is).
This also resolves the problem of users getting confused over which return values are safe to edit (references) and which ones aren't (const references): if it's a Get* method, you cannot, if it is a getter, you can.
I've mentioned this before, I think, but your API and documentation is not really great (sorry). And my speed and up-to-dateness are not. I'm still keen to find some way to join forces.