box2d释放的冲动

时间:2012-02-06 10:37:12

标签: iphone cocos2d-iphone box2d

当我松开手指时,我想施加冲动,但是我无法让它发挥作用。对象体不会重新对我的输入行动。所以这是我的发布代码。

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (mouseJoint != nil) 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);

float distanceX = location.x-170;
float distanceY =location.y-270;
float distance = sqrtf(distanceX*distanceX+distanceY*distanceY);
CGFloat angle = atan2f(distanceY,distanceX);

// Apply an impulse to the body, using the angle
tailBody->ApplyLinearImpulse(b2Vec2(-distance*cosf(angle)/4+100,-distance*sinf(angle)/4+100), tailBody->GetPosition());

if (mouseJoint) {
    world->DestroyJoint(mouseJoint);
    mouseJoint = NULL;
}


}

代码中是否缺少某些内容?

0 个答案:

没有答案