can anybody help me to convert this objective-c code to android java.
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (_mouseJoint != NULL) return;
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
if (_paddleFixture->TestPoint(locationWorld)) {
b2MouseJointDef md;
md.bodyA = _groundBody;
md.bodyB = _paddleBody;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 1000.0f * _paddleBody->GetMass();
_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
_paddleBody->SetAwake(true);
}
}
I tried below is my code but getting exception. java.lang.nullpointer . Is anything wrong ?
public boolean ccTouchesBegan(MotionEvent event) {
if (_mouseJoint != null){
return true;
}
else{
CGPoint convertedLocation = CCDirector.sharedDirector().convertToGL(CGPoint.make(event.getX(), event.getY()));
Vector2 locationWorld = new Vector2(convertedLocation.x/PTM_RATIO, convertedLocation.y/PTM_RATIO);
// return CCTouchDispatcher.kEventHandled;
//_mouseJoint.setTarget(locationWorld);
if(_paddleFixture.testPoint(locationWorld)){
MouseJointDef md = new MouseJointDef();
md.bodyA = _body;
md.bodyB = _paddleBody;
md.target.set(locationWorld);
md.collideConnected = true;
md.maxForce = (float)(1000.0f * _paddleBody.getMass());
_mouseJoint = (MouseJoint) _world.createJoint(md);
_paddleBody.setAwake(true);
}
}
//return CCTouchDispatcher.kEventHandled;
return true;
}