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

I'm getting the following error when raycasting:
Code:
Assertion failed: (0.0f <= lower && lower <= input.maxFraction), function RayCast, file ../Box2D/Collision/Shapes/b2PolygonShape.cpp, line 253.


I'm raycasting the following bodies:
Code:
b2Def.polygon.SetAsBox(400/30, 50/30);
b2Def.body.position.x = 400/30;
b2Def.body.position.y = 550/30;
b2Def.body.type = b2Body.b2_staticBody;
b2Def.body.fixedRotation = true;
b2Def.body.allowSleep = true;
mBody = mPhysicsWorld.CreateBody(b2Def.body);
b2Def.fixture.shape = b2Def.polygon;
b2Def.fixture.friction = 0;
b2Def.fixture.density = 0;
b2Def.fixture.restitution = 0;
mBody.CreateFixture(b2Def.fixture);
bodies.push(mBody);

b2Def.polygon.SetAsBox(1000/30, 50/30);
b2Def.body.position.x = 500/30;
b2Def.body.position.y = 50/30;
b2Def.body.type = b2Body.b2_staticBody;
b2Def.body.fixedRotation = true;
b2Def.body.allowSleep = true;
mBody = mPhysicsWorld.CreateBody(b2Def.body);
b2Def.fixture.shape = b2Def.polygon;
b2Def.fixture.friction = 0;
b2Def.fixture.density = 0;
b2Def.fixture.restitution = 0;
mBody.CreateFixture(b2Def.fixture);
bodies.push(mBody);
         
b2Def.polygon.SetAsBox(400/30, 200/30);
b2Def.body.position.x = 1500/30;
b2Def.body.position.y = 550/30;
b2Def.body.type = b2Body.b2_staticBody;
b2Def.body.fixedRotation = true;
b2Def.body.allowSleep = true;
mBody = mPhysicsWorld.CreateBody(b2Def.body);
b2Def.fixture.shape = b2Def.polygon;
b2Def.fixture.friction = 0;
b2Def.fixture.density = 0;
b2Def.fixture.restitution = 0;
mBody.CreateFixture(b2Def.fixture);
bodies.push(mBody);


The error occurs when the raycasting hits the last body.

The errors seems the same as this one:
http://www.box2d.org/forum/viewtopic.php?f=4&t=4559
Using addEventListener with wck ?

I noticed yesterday that once i switch to the next world / via gotoAndStop(currentFrame+1),
i sometimes recieve an error message regarding event handlers that i had added with addEventListener. I guess they are not removed properly once the current world is destroyed.
Usually i am using listenWhileVisible. However i have very few classes that extend movieclip and therefore they dont have those methods.
Is there any way to tell wck to remove those addEventListeners ?

Cheers
Frnk:

Re: Events: This is the default behavior in Flash. You have to manually remove event listeners. "listenWhileVisible" is a wrapper for "addEventListener" that will automatically remove event listeners when the display object is removed from the stage. You don't have to be inside the World class (or BodyShape, or anything that extends Entity) to use it though. For example, lets say you have MyClass that doesn't extend anything but has a reference to the world. You can call:
Code:
world.listenWhileVisible(world, Event.ENTER_FRAME, someMethodDefinedByMyClass);

The listener will be removed when world is destroyed. Although in this case you could also listen to StepEvent.STEP, which will only be dispatched while the world is active.

There is also Util.stopInvisibleEnterFrame(), which will block enter frame events for display objects not on the stage. The listeners will still reside in memory though, unless you use weak references when calling addEventListener. So basically its complicated.

Re: RayCasts: Diving into this issue today.
RayCasts: RayCasts are fixed. Well, actually, they were never broke. If you have an error in your callback function, it wont be reported during debugging. Alchemy blocks it. The ray cast test bed that sketchbook provided had this problematic line:
Code:
f.m_body.GetUserData().alpha -= .2

The user data in this case was null.
The trouble i have is getting a world reference to the MovieClip constructor in time before it's initialized. Thanks to flash, the order of initialization of displayobjects isn't controllable and i'm getting the null reference error :/

I wanted to have the world reference already for the constructor

Code:
public class PalmTree extends MovieClip
   {   
      private var _world:World;
      
      public function PalmTree() {
                _world = StatsCounter.world;
                _world.listenWhileVisible(this, Event.ADDED_TO_STAGE, playAtFrame);

Otherwise i could have waited for ADDED_TO_STAGE Event and then trying to get the world reference would probably work.
Still getting the RayCast error (im not using the wck framework, just the port)
Code:
Assertion failed: (0.0f <= lower && lower <= input.maxFraction), function RayCast, file ../Box2D/Collision/Shapes/b2PolygonShape.cpp, line 253.
[object AlchemyExit]

   at <anonymous>()
   at <anonymous>()
   at Box2DAS.Dynamics::b2World/RayCast()[C:\Users\Maarten\Documents\My Dropbox\FastConstantMoving\src\Box2DAS\Dynamics\b2World.as:109]
   at FastConstantMoving/MouseUpdate()[C:\Users\Maarten\Documents\My Dropbox\FastConstantMoving\src\FastConstantMoving.as:103]
   at FastConstantMoving/Update()[C:\Users\Maarten\Documents\My Dropbox\FastConstantMoving\src\FastConstantMoving.as:132]


RayCasting like this:
Code:
mPhysicsWorld.RayCast(TryGrapple, mPlayer.Body.GetPosition(), new V2(mPlayer.Body.GetPosition().x+10, mPlayer.Body.GetPosition().y));


I've commented out all the code inside the TryGrapple function but I keep getting the error:
Code:
private function TryGrapple(fixture:b2Fixture, point:V2, normal:V2, fraction:Number):void
{
}


if you have the debug player you can try it out here (just keep on clicking till you get the error):
http://www.vanaremmedia.com/dump/FastCo ... oving.html
Stryke wrote:
I've commented out all the code inside the TryGrapple function but I keep getting the error:


Your callback must return a number. Just return fraction as it is passed in.
Frnk wrote:
I wanted to have the world reference already for the constructor


constructors for display objects are terrible. You could just extend Entity, override the pseudo-constructor "create()" and do:
Code:
public override function create():void {
    world = Util.findAncestorOfClass(this, wck.World) as wck.World;
    world.ensureCreated();
}
mayo:

I have to thank you for two things. The first being the script itself, but much more importantly for introducing me to jsfl in the first place. Wow, does this open up some possiblities. This is something that I can't believe I haven't heard about before, considering I've worked pretty heavily with Flash for 2 years.
Thanks mayo, should have figured that one out by looking at the testbed 😆 but thanks.

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