AS3 2.1 Port (Alchemy), WCK Update and Kinematic Demos

http://www.sideroller.com/wck/

I've just updated World Construction Kit to use Box2D 2.1 (the latest version in SVN). The big update here is Kinematic Bodies. You can now create motion tweens in Flash and your animated bodies will interact properly in Box2D.

The Alchemy port can also be used on its own. There's a "HelloWorld" project in the Box2DAS folder that demonstrates how to use this port outside of WCK.
This is pretty impressive at first glance, and I'm sure it will be more so once I get a chance to dig into it.
Wow these are great demos. I'm just getting started with Box2D, working with the regular AS3 library. I like the use of Component/Component Inspector to set properties for each clip. This is cool option to just throw an element on the stage and give it physical properties. It also get around the rendering problem. Of course this is just the perspective of a rank amateur.
Updated: Added a simple platformer level to the demos & another one that lets you draw shapes (like crayon physics).
This is fantastic stuff! Very fast and extremely capable.

I think I found a bug though.

In the Hello.as example, change this...

Code:
...
public function Hello() {
   b2Base.initialize();
   world = new b2World(new V2(0, 10));
   var body:b2Body;
   b2Def.circle.m_radius = 5 / scale;
...


to this...

Code:
...
public function Hello() {
   b2Base.initialize();
   world = new b2World(new V2(0, 10));
   world.SetGravity(new V2(0, 10)) // <--------- added line
   var body:b2Body;
   b2Def.circle.m_radius = 5 / scale;
...


I think this shouldn't really do anything, right? We are just setting the gravity to a new value that is actually the same as it was upon instantiation of the world. But instead the gravity somehow gets skewed rightward when running it. Which is odd since no where do we tell it to change the x portion at all.
Also, on a related note...

Switching that line to this...

Code:
...
public function Hello() {
   b2Base.initialize();
   world = new b2World(new V2(0, 10));
   trace(world.GetGravity().toP()) // <--------- traces "(x=0, y=0)"
   var body:b2Body;
   b2Def.circle.m_radius = 5 / scale;
...


... demonstrates that world.GetGravity() is returning a V2 with coordinates of (0, 0) rather than (0, 10), as would be expected. I'm not sure if this is a symptom of the same cause, or what, but something is definitely off.

Also, world.SetGravity(new V2(1, 1)) results in a "The specified range is invalid" error. Also I don't have an example case for you (yet), but in my own project when attempting to call SetGravity each frame with a certain circular loop pattern for x and y, it rapidly eats up over a gig of memory and then the player crashes. I'll try to get this to do the same behavior for Hello.as but I don't have anything for you yet.

Another thing: tracing the value of the radius of the only fixture of the 'kine' body [ trace(kine.m_fixtureList.m_shape.m_radius) ] yields a value of 0, but it should be 5/3 I think.

Anyway, not trying to nit pick or anything, I realize this is an early version. Honestly, the way you've adapted this to Alchemy is phenomenal and I'm definitely planning on using this in my projects. Thanks x100000 for your efforts!
You are right, world.SetGravity() was broken. WCK doesn't use the built in gravity so I never noticed. I've uploaded a fixed version.

The issue was that b2World's pointer to the gravity vector in alchemy memory was pointing to the wrong place. If you run the project in the "probe" folder it'll analyze the C++ class structure and generate a bunch of getters and setters (in the output panel) for use in AS3. b2World.as hadn't had it's getters and setters updated to 2.1.

Thanks for this. I was hoping someone like you would come along and help me fill in the gaps.
No problem! Btw the gravity stuff is working for me but kine.m_fixtureList.GetShape().m_radius is still returning 0--it could be that I am trying to access this in the wrong way, though--is there another way to get at the radius of the fixture attached to that body?

The project I'm (potentially) using this for is going to be using a lot of the available functionality (such as SetGravity) to modify the characteristics of the world and its bodies as they are running. So I will let you know if I run into any more problems on that front, especially after next week when I have more time to test.
Just uploaded a new version that should fix the m_radius issue. Yes, let me know if you run into anything else.
Great, seems to work perfectly (I needed it to do some basic shape drawing).

Do you know if/when contact lists and/or sensors will be implemented? I replaced the old physics engine I was using (not box2d) in my project with your alchemy port and I think once I have the ability to detect collisions for a non-solid shape and a solid one, I'll be up to the feature level I was at before the change. Once I have a way to do this I'll be comfortable adding new features which should enable me to test more of the functionality of your port.

I absolutely don't mean to rush you though--this is a long term project and I have other aspects of it that I can work on in the meantime. Thanks again!

Original thread: https://box2d.org/forum/viewtopic.php?t=4105