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

I was just reading back and sketchbookgames also made a comment about your package structure, mayobutter:

sketchbookgames wrote:
Some improvements i would like to make.

wrap your code into com/sideroller
Including:
  • extras
  • gravity
  • misc
  • shapes
  • wck
  • (and maybe Box2DAS)


I'd agree with this and would suggest even more fine grained, structured packaging. But I hear you saying:

mayobutter wrote:
I've seen other packages organized this way. Personally I find the deep folder hierarchy extremely cumbersome. That, and when defining symbols in Flash it is nicer to type "shapes.Box" as the base class rather than "com.sideroller.shapes.Box".


Very valid, it's even more of a pain in the ass when you've got subdomains and .com.au etc to deal with on top. So anyway I'd propose a meet in the middle solution:

Structure your base classes using normal package conventions, but create convenience classes for commonly used objects (like you have done with shapes) in shallowly nested packages. This way you can provide convenience AND great code organisation all at once. 😉
Hmm, I followed the steps in the recentl posted write-up. I figured since it was so well laid out I would finally give WCK a go. Strangely enough, when I got to the step saying 'Check Export SWC' I figured, what the hell would I want to do that for? I don't want a package, I want the swf... so I didn't. Guess what? I got errors. Why is that? I have never run into this before.. maybe its because I don't use the IDE much, but does anyone know why?
VengantMjolnir wrote:
Hmm, I followed the steps in the recentl posted write-up. I figured since it was so well laid out I would finally give WCK a go. Strangely enough, when I got to the step saying 'Check Export SWC' I figured, what the hell would I want to do that for? I don't want a package, I want the swf... so I didn't. Guess what? I got errors. Why is that? I have never run into this before.. maybe its because I don't use the IDE much, but does anyone know why?


No idea. I think it is an Alchemy thing. The resultant SWC is not used. Flash works in mysterious ways.
Hello,

Is it possible to change attributes like friction, restitution or density on the fly?


EDIT:: Just found this, seems to work fine 🙂
Code:
// Change property of body, in this case friction (there are other methods for other properties)
this.b2body.GetFixtureList().SetFriction(friction);
Great job on this Mayo. I'm in the process of switching my game to your Alchemy version.

I was trying to set a shape's vertices like the Box2D Wiki (http://www.box2d.org/wiki/index.php?title=Manual/C%2B%2B#Polygon_Definitions) suggested:

Code:
var fd:b2FixtureDef = new b2FixtureDef();
fd.density = d;

var shape:b2PolygonShape= new b2PolygonShape();
shape.m_vertexCount=6;
shape.m_vertices[0]=new V2( -45/ engine.physScale, 35/ engine.physScale);
shape.m_vertices[1]=new V2( -42/ engine.physScale, 13/ engine.physScale);
shape.m_vertices[2]=new V2( -26/ engine.physScale, -13/ engine.physScale);
shape.m_vertices[3]=new V2( -1/ engine.physScale, -37/ engine.physScale);
shape.m_vertices[4]=new V2( 31/ engine.physScale, -8/ engine.physScale);
shape.m_vertices[5]=new V2( 45/ engine.physScale, 35/ engine.physScale);
fd.shape = shape;


But that didn't work. I changed it to this and it worked:
Code:
var fd:b2FixtureDef = new b2FixtureDef();
fd.density = d;

var shape:b2PolygonShape= new b2PolygonShape();
var vertices:Vector.<V2>=new Vector.<V2>();
vertices[0]=new V2( -45/ engine.physScale, 35/ engine.physScale);
vertices[1]=new V2( -42/ engine.physScale, 13/ engine.physScale);
vertices[2]=new V2( -26/ engine.physScale, -13/ engine.physScale);
vertices[3]=new V2( -1/ engine.physScale, -37/ engine.physScale);
vertices[4]=new V2( 31/ engine.physScale, -8/ engine.physScale);
vertices[5]=new V2( 45/ engine.physScale, 35/ engine.physScale);
shape.Set(vertices);


I had to create a new vector and pass it into the shape's Set method. It's not a big deal but it doesn't seem to work the same way that the Wiki suggests. I could just being doing it wrong. If not it might cause some confusion for those using the Wiki as a reference.

Either way this is amazing and I can't thank you enough for the time you put into it.

Thanks,
Bryan
jaeta: After I merge V2 & b2Vec2 the syntax in the wiki should work properly. If you follow the chain of getters & setters as they work now you'll see why it doesn't work (every vertex assignment creates a new V2 vector which is promptly lost to the void).
hey I just have to say again that WCK is amazing.
how can i "skin" a box 2d object?
I'm trying shape decomposition that will fit an object.
thanks
Just finished porting my game over to the Alchemy version from the native Actionscript version and I'm loving the speed increase. I am running into a bug though, that pops up at seemingly random times:

Assertion failed: (0 <= index && index < m_count), function GetVertex, file ../Box2D/Collision/b2Distance.h, line 103.

The stack on this is:

at <anonymous>()
at <anonymous>()
at Box2DAS.Dynamics::b2World/HandleStep()[E:\Applications and Tools\Box2D_Alchemy_2.1\lib\Box2DAS\Dynamics\b2World.as:168]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at Box2DAS.Common::b2EventDispatcher/dispatchEvent()[E:\Applications and Tools\Box2D_Alchemy_2.1\lib\Box2DAS\Common\b2EventDispatcher.as:27]
at Box2DAS.Dynamics::b2World/Step()[E:\Applications and Tools\Box2D_Alchemy_2.1\lib\Box2DAS\Dynamics\b2World.as:164]

Any thoughts on what's going on?

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