
Untitled
By: a guest on
Aug 9th, 2012 | syntax:
None | size: 1.22 KB | hits: 14 | expires: Never
How to send prototype method as a callback in javascript?
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;
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);
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;
var _this = this;
this.world.QueryAABB(function(fix){
_this.getBodyCB(fix);
}, aabb);
this.world.QueryAABB(this.getBodyCB.bind(this), aabb);