我有原型方法,它由我正在使用的 Box2D API 的回调激活。回调可以到达函数,但它不是函数的正确实例。获取回调以调用此.prototype 类的正确语法是什么。
对 Box2D API 的调用:
Box2d.prototype.getBodyAtMouse = function() {
this.mousePVec = new this.b2Vec2(this.mouseX/this.SCALE, this.mouseY/this.SCALE);
var aabb = new this.b2AABB();
aabb.lowerBound.Set(this.mouseX/this.SCALE - 0.001, this.mouseY/this.SCALE - 0.001);
aabb.upperBound.Set(this.mouseX/this.SCALE + 0.001, this.mouseY/this.SCALE + 0.001);
this.selectedBody = null;
var _this = this;
this.world.QueryAABB(_this.getBodyCB, aabb);
return this.selectedBody;
}
这是被调用的 box2D API 方法:
b2World.prototype.QueryAABB = function (callback, aabb) {
var __this = this;
var broadPhase = __this.m_contactManager.m_broadPhase;
function WorldQueryWrapper(proxy) {
return callback(broadPhase.GetUserData(proxy));
};
broadPhase.Query(WorldQueryWrapper, aabb);
}
这是我希望 API 正确引用的回调:
Box2d.prototype.getBodyCB = function(fixture)
{
if(fixture.GetBody().GetType() != this.b2Body.b2_staticBody) {
if(fixture.GetShape().TestPoint(fixture.GetBody().GetTransform(), this.mousePVec)) {
selectedBody = fixture.GetBody();
return false;
}
}
return true;
}