1
我正试图移动触摸移动精灵。但是当两个精灵在那里时,我正在接触两个精灵。这就是为什么精灵不能正常移动。cocos2D和Box2D:如何获得精确触摸的精灵?
- (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
。但在这个如果我触摸第二个精灵我碰到第一个精灵和第二个精灵..两个精灵位置是相同的...
我在我的代码加入我的一些代码 – Hiren 2012-08-17 08:25:50
'如果(fixture->测试点(locationWorld))'这个情况对于两个精灵 – Hiren 2012-08-17 08:46:10
是真的我个人使用QueryCallback..indows代码风格..http://s463.codeinspot.com/q/1728579 – Guru 2012-08-17 08:51:59