我正在尝试在触摸移动时移动精灵。但是当有两个精灵时,我会接触到两个精灵。这就是精灵不能正常移动的原因。
- (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);
for(int i=0;i<[mutArrFixtures count];i++)
{
b2Fixture *fixture;
[[mutArrFixtures objectAtIndex:i] getValue:&fixture];
if (fixture->TestPoint(locationWorld)){
for(int j=0; j<[mutArrPaddleBody count]; j++)
{
b2Body *body;
[[mutArrPaddleBody objectAtIndex:j] getValue:&body];
b2MouseJointDef md;
if(body == fixture->GetBody())
{
md.bodyA = _groundBody;
md.bodyB = body;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 1000.0f * body->GetMass();
_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
body->SetAwake(true);
}
}
}
}
}
我有一个 b2Fixture 数组mutArrFixtures
和一个 b2body 数组mutArrPaddleBody
。但是在这里,如果我触摸第二个精灵,我会触摸到第一个精灵和第二个精灵..两个精灵的位置是相同的......