Hi Guys, I'm starting to explore conversion of the Mousejoint testbed code in my game to accomodate multitouch, and referring to Apple docs on handling multitouch input.
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html
My ccTouchesBegan code provides two memorized touchpoints in my main GameScene.m file :
The trick is to ensure a second mouseJoint is properly attached and tracked in a two-player game, and a correct strategy is the block for me right now. Any ideas appreciated!
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html
My ccTouchesBegan code provides two memorized touchpoints in my main GameScene.m file :
Code:
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *sortedTouches = [[touches allObjects] sortedArrayUsingSelector:@selector(compareAddress:)];
UITouch *touch1 = NULL;
UITouch *touch2 = NULL;
touch1 = [sortedTouches objectAtIndex:0];
if ([touches count] > 1) {
UITouch *touch2 = [sortedTouches objectAtIndex:1];
}
CGPoint location1 = [touch1 locationInView: [touch1 view]];
location1 = [[Director sharedDirector]convertToGL:location1];
if(touch2 != NULL) {
CGPoint location2 = [touch2 locationInView: [touch2 view]];
location2 = [[Director sharedDirector]convertToGL:location2];
}
// working mousejoint for single touch
m_mouseWorld.Set(location1.x/PTM_RATIO, location1.y/PTM_RATIO);
if (m_mouseJoint != NULL)
{
return;
}
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = m_mouseWorld - d;
aabb.upperBound = m_mouseWorld + d;
QueryCallback callback(m_mouseWorld);
world->QueryAABB(&callback, aabb);
if (callback.m_fixture) // check for mousejoint, which body and/or location
{
b2Body* mbody = callback.m_fixture->GetBody();
//if (temp != ) {
b2MouseJointDef md;
md.body1 = groundBody; // add GroundBody property
md.body2 = mbody;
md.target = m_mouseWorld;
#ifdef TARGET_FLOAT32_ISFIXED
md.m_frequencyHz = 60.0f;
md.m_dampingRatio = 1.0f;
md.maxForce = (mbody->GetMass() < 16.0)?
(1000.0f * mbody->GetMass()) : float32(16000.0);
#else
md.maxForce = 1000.0f * mbody->GetMass();
#endif
m_mouseJoint = (b2MouseJoint*)world->CreateJoint(&md);
mbody->WakeUp();
// }
}
}
NSArray *sortedTouches = [[touches allObjects] sortedArrayUsingSelector:@selector(compareAddress:)];
UITouch *touch1 = NULL;
UITouch *touch2 = NULL;
touch1 = [sortedTouches objectAtIndex:0];
if ([touches count] > 1) {
UITouch *touch2 = [sortedTouches objectAtIndex:1];
}
CGPoint location1 = [touch1 locationInView: [touch1 view]];
location1 = [[Director sharedDirector]convertToGL:location1];
if(touch2 != NULL) {
CGPoint location2 = [touch2 locationInView: [touch2 view]];
location2 = [[Director sharedDirector]convertToGL:location2];
}
// working mousejoint for single touch
m_mouseWorld.Set(location1.x/PTM_RATIO, location1.y/PTM_RATIO);
if (m_mouseJoint != NULL)
{
return;
}
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = m_mouseWorld - d;
aabb.upperBound = m_mouseWorld + d;
QueryCallback callback(m_mouseWorld);
world->QueryAABB(&callback, aabb);
if (callback.m_fixture) // check for mousejoint, which body and/or location
{
b2Body* mbody = callback.m_fixture->GetBody();
//if (temp != ) {
b2MouseJointDef md;
md.body1 = groundBody; // add GroundBody property
md.body2 = mbody;
md.target = m_mouseWorld;
#ifdef TARGET_FLOAT32_ISFIXED
md.m_frequencyHz = 60.0f;
md.m_dampingRatio = 1.0f;
md.maxForce = (mbody->GetMass() < 16.0)?
(1000.0f * mbody->GetMass()) : float32(16000.0);
#else
md.maxForce = 1000.0f * mbody->GetMass();
#endif
m_mouseJoint = (b2MouseJoint*)world->CreateJoint(&md);
mbody->WakeUp();
// }
}
}
The trick is to ensure a second mouseJoint is properly attached and tracked in a two-player game, and a correct strategy is the block for me right now. Any ideas appreciated!