我有一个CCSprite
连接到身体的b2world
. 当有人触摸它时,我想用触摸位置移动它。使用正常的精灵可以正常工作,但使用有身体的精灵 - 它没有。它得到了触摸但不移动精灵(身体跟随精灵还是相反?)我应该怎么做?相对于触摸施加力是一个问题..
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView: [touch view]];
//detect a touch ont the button
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
CGPoint location=[[CCDirector sharedDirector] convertToGL: currentPosition];
CCSprite *tempSprite = (CCSprite *) b->GetUserData();
if( tempSprite.tag==2 )
{
if(CGRectContainsPoint([tempSprite boundingBox], location))
{
tempSprite.position=location;
NSLog(@"touched");
}
}
}
}