I created a demo with touch events which works fine on the browser and the ipad simulator using cocos2dx - javascript bindings, but it does not return the polyshape or body under the touch point. It just returns a shape.
These are my touch events.
Code: Select all
onTouchesBegan:function (pTouch,pEvent){
self.mouse = this.touch2point(pTouch[0].getLocation().x, pTouch[0].getLocation().y);
this.mouseBody.p = this.touch2point(pTouch[0].getLocation().x, pTouch[0].getLocation().y);
if(!self.mouseJoint) {
var point = this.touch2point(pTouch[0].getLocation().x, pTouch[0].getLocation().y);
var shape = this.space.pointQueryFirst(point, GRABABLE_MASK_BIT, cp.NO_GROUP);
if(shape){
var body = shape.body;
var mouseJoint = self.mouseJoint = new cp.PivotJoint(this.mouseBody, body, this.touch2point(pTouch[0].getLocation().x, pTouch[0].getLocation().y));
mouseJoint.maxForce = 50000;
mouseJoint.errorBias = Math.pow(1 - 0.15, 60);
this.space.addConstraint(mouseJoint);
}
}
},
onTouchesEnded:function (pTouch,e){
self.mouse = this.touch2point(pTouch[0].getLocation().x, pTouch[0].getLocation().y);
if(self.mouseJoint) {
this.space.removeConstraint(self.mouseJoint);
self.mouseJoint = null;
}
},
onTouchesMoved:function(pTouch,e){
self.mouse = this.touch2point(pTouch[0].getLocation().x, pTouch[0].getLocation().y);
var newPoint = v.lerp(this.mouseBody.p, self.mouse, 0.25);
this.mouseBody.v = v.mult(v.sub(newPoint, this.mouseBody.p), 60);
//this.mouseBody.p = cc.p(newPoint.x,140);
this.mouseBody.p = newPoint;
},
After that, any call to shape.getbody() crashes the application coz it doesn't get the body under the touch point.
In the xcode debugger this is the error
Thread 1: EXC_BAD_ACCESS ( code=1,address=0x4) and it stops on line CP_DefineShapeStructGetter(cpBody*, body, Body)
Is there an issue with my touch events coz it works fine in the browser and on the simulator.
Cheers and thanks
Amit