Hi Doug,
I have this code:
Code:
public var circle:qb2CircleShape
public function Main():void
{
var world:qb2World = qb2Stock.newDebugWorld(new amVector2d(0, 30), this.graphics, stage);
world.start();
circle = qb2Stock.newCircleShape(new amPoint2d(100, 100), 50, 1);
world.addObject(circle);
circle.restitution = .0
var rectangle:qb2PolygonShape = qb2Stock.newRectShape(new amPoint2d(200, 400), 150, 15, 0);
world.addObject(rectangle);
//
//var body:qb2Body = qb2Stock.newLineBody(new amPoint2d(300, 300), new amPoint2d(400, 400), 10, 1, qb2Stock.ENDS_ROUND);
//world.addObject(body);
var walls:qb2StageWalls = new qb2StageWalls(stage);
world.addObject(walls);
world.addEventListener(qb2UpdateEvent.PRE_UPDATE, onPreUpdate);
qb2Keyboard.makeSingleton(stage);
//world.addEventListener(qb2ContactEvent.PRE_SOLVE, onContactStarted);
//circle.addEventListener(qb2ContactEvent.PRE_SOLVE, onPreSolve);
rectangle.addEventListener(qb2ContactEvent.PRE_SOLVE, onPlatformPresolve);
}
private function onPlatformPresolve(e:qb2ContactEvent):void
{
if (e.contactNormal.y == 1) e.disableContact();
}
private function onPreSolve(e:qb2ContactEvent):void
{
//trace(e.type == qb2ContactEvent.PRE_SOLVE);
if (e.contactNormal.y == 1) e.disableContact();
}
What I want to do is to disable the contact. I got error only when I hit the platform from below.
Here is the error:
Code:
[Fault] exception, information=Error: Contacts can only be enabled/disabled for "pre-solve" events.
EDIT: This code inside qb2BaseContactEvent looks suspicious:
Code:
private function checkForError():void
{
if ( type != qb2ContactEvent.PRE_SOLVE || type != qb2SubContactEvent.SUB_PRE_SOLVE )
throw new Error("Contacts can only be enabled/disabled for \"pre-solve\" events.");
}
Which means that I'll always have the error unless the type is both PRE_SOLVE and SUB_PRE_SOLVE, because if either of them is not the correct type it will return "true" and throw the error.
EDIT3: I commented out SUB_PRE_SOLVE and it works for now, but since I didn't wrote the lib.. I'm not sure whether this will not break something else. Doug, can you confirm that the change is okay? The version of qb2 I'm using is the version from the SVN.
EDIT2: Here is something else that I can't make work:
Code:
//var effect:qb2GravityField = new qb2GravityField(true);
var effect:qb2GravityField = new qb2GravityField(false);
effect.gravity.y = 9.8;
//effect.gravity = new amVector2d(0, 30);
//effect.disableForType(qb2CircleShape);
//effect.disableForInstance(circle);
//effect.enableForType(qb2CircleShape);
effect.enableForInstance(circle);
world.addObject(effect);
I tried different variants.. but I can't control the circle instance (it's the same circle from the example in the prev post). If I set the field to be ubiquitous then I can't filter the circle and it applies to everything, if I set ubiquitous to false, then I can't make the filter to act only on the circle.. Probably I don't understand something.. but it doesn't work for me.