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

@mayobutter, or wck users.

traditionally box2d (at least 2.01 which i was used to) dispatches contactPersist events repeatedly until the contact no longer exists. i understand using alchemy this would slow things down... and its possible that the box2d core has changed this too in 2.1 i haven't checked.

to the point: using wck, i am trying to loop through the contact list and resend existing contacts on enter frame. but I seem to be doing something wrong.

i seem to get count > 0 when i first hit something, but if i stay inside the object, it goes back to 0.

wondering if you have a recommendation for getting back to "contactPersist" type functionality.

here's some stuff I'm using basically grabbed from your boxMan class.
Code:
public var contacts:ContactList;

public override function create():void {
   reportBeginContact = true;
   reportEndContact = true;
   fixedRotation = true;
   super.create();
   listenWhileVisible(this, ContactEvent.BEGIN_CONTACT, handleContact);
   contacts = new ContactList();
   contacts.listenTo(this);
}

private function doCollision():void{ //called on enter frame
   var count:int = 0;
   contacts.forEach(function(keys:Array, c:ContactEvent) {
      count++
      //handleContact(c);
   });
   trace("count: "+count);
   contacts.clean();
}
sketchbook: Sounds like you want the pre-solve (or maybe post-solve) events:
Code:
reportPreSolve = true;
listenWhileVisible(this, ContactEvent.PRE_SOLVE, handlePersistContact);

They will fire each timestep. Although the code you're using should work fine. I prefer to just listen to begin & end events, because of the overhead you mentioned.
thanks for your reply, pre and post solvers will be very helpful to me later, however i failed to mention i was dealing with sensors. for which they do not apply. i manged to meet my current needs by adding an enter frame listener to the contact shape on BeginContact and removing it on EndContact, i think i was mis-understanding the contact list in my previous post.

all is well again,

i added some notes to the wiki i appended to the box2d wiki
http://www.box2d.org/wiki/index.php?title=WCK_Documentation

i will try to add more there when i feel i have a clear understanding of various parts of the wck framework.
I'm changing the maskBits of a shape on the fly to either 0 or 1. The problem with this is that it doesnt refilter until the contact has ended and begins again. I know in the old version of Box2D, you could refilter a shape, but I don't seem to see that functionality in the Alchemy port. What is the best way to approach this? Thanks.
helios02: You should be able to call "Refilter()" on a b2Fixture. Is this not working? If you set the maskBits via "SetFilterData()" it should Refilter the fixture automatically.
WCK loaded into a swf container (also called a shell):

trying to load my WCK game into a container and yikes!

first error i ran into was

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at misc::Input$/initialize()
at wck::WCK()

because stage was null
wckLib.misc.Input.as:: stage: null

so i made a slight change to WCK.as
Code:
public function WCK() {
   b2Base.initialize();
   addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
public function addedToStage(e:Event):void{
   trace("WCK.as addedToStage()");
   removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
   
   Input.initialize(stage);
}

so now WCK will wait to call Input.initialize until it has a stage. (many things in WCK seem to already listen for added to stage and removed from stage to determine with to create and destroy them selves, it seemed odd to me that WCK.as it self did not already have that set up.

now with the null stage out of the way, i try to run it in the shell and i get no errors. But everything just falls. BodyShapes i had joined together with joints which work stand alone, do not work in the swf container. so all the body shapes just fall.
without an error, its hard to decide a good place to look for what has gone wrong.

maybe ill start adding traces in the joint code and BodyShape code to see what order things are firing in. any assistance would be appreciated. thanks.
creation process seems just about the same between stand alone and loaded in the shell.

stand alone I'm actually getting one BodyShape creation call before the World creation call, which seems to be odd, but it works stand alone. in the shell that BodyShape is still created just after the World which seems to be more right, but things are broken in the shell.

i also added some walls to keep the falling pieces on screen, after they fall from the failed joints.

upon further analysis, i can still click and drag these items and everything seems to work in them other than the joints not attaching to them in the beginning.

ill turn on debug draw, to see if there is something odd about positioning when loaded into the shell, and ill add a bunch of joints so that if there is a positioning issue something will hopefully get caught by a different joint allowing me to confirm that the joints are doing something.
ok, bodies shapes and everything look normal in debug draw, i was able to discern that the some of the joints were making contact with the outer walls, which shows that this is due to the X and Y positioning of the game withing the loading shell.

i set the X and Y to zero and my joints are now working most of the way. there is still some strangeness.

@Mayobutter, what part of the code tells the joints which bodies to attach to? i can write some code to make it still work under these circumstances.
my first guess would be Joint.as locateBodies() but this seems to have more to do with context/class type handling, and nothing to do with a position or area to grab from.
sketchbook: When joints are created, they try to "magically" find their BodyShapes by using "getObjectsUnderPoint" to locate any BodyShapes directly under the joint. If this fails, you can always specify the BodyShapes manually by naming them and setting the "target1Name" (the name of a BodyShape) and "target2Name" (the name of a BodyShape or Joint). It should work though... I am curious why it is failing for you.

Good catch on the WCK constructor. I never anticipated it being used by anything other than the root document class.

EDIT: The relevant piece of code you are looking for is:

Code:
var objs:Array = Util.getObjectsUnderPointByClass(world, localToGlobal(new Point(0, 0)), BodyShape, autoFind, exclude);


Which calls Flash's getObjectsUnderPoint.
🙁 more positioning problems, not related to if its in a shell or not.

lets imagine i have a snow man art peice.
i set its Linkage to wck.BodyShape.
i make a black circle, which i will turn invisible later, and set its Linkage to shapes.Circle
this circle is centered on its axis.

now i put 3 circles into my snow man BodyShape.
in this way the snowMan acts as a body.
and the black circles act as shapes.

make sure its inside my world.

turn on debug draw
publish.

the shapes are offset from where they belong. if i move my snowman around in my world the offset gets better or worse. something is wrong with the way the positioning of shapes when nested inside of bodies in wck.

i will post a file momentarily.

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