0
본문에 첨부 된 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");
}
}
}
}
마우스 조인트가 가장 좋습니다. – Guru