我以前也遇到过同样的问题。我为我的游戏修正了这个问题,修改了journey.m文件中的-touchesMoved方法。
只需复制以下代码并将其替换为
-touchesMoved
中的方法
Joystick.m
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (isTracking == YES)
{
for (UITouch *touch in touches)
{
CGPoint touchPoint = [touch locationInNode:self];
if (sqrtf(powf((touchPoint.x - self.anchorPointInPoints.x), 2) + powf((touchPoint.y - self.anchorPointInPoints.y), 2)) <= thumbNode.size.width)
{
CGPoint moveDifference = CGPointMake(touchPoint.x - self.anchorPointInPoints.x, touchPoint.y - self.anchorPointInPoints.y);
thumbNode.position = CGPointMake(self.anchorPointInPoints.x + moveDifference.x, self.anchorPointInPoints.y + moveDifference.y);
}
else
{
double vX = touchPoint.x - self.anchorPointInPoints.x;
double vY = touchPoint.y - self.anchorPointInPoints.y;
if (!(vX > 256 || vY > 256)) //Touchpoint should be within limits. Change the values to suit your situation.
{
double magV = sqrt(vX*vX + vY*vY);
double aX = self.anchorPointInPoints.x + vX / magV * thumbNode.size.width;
double aY = self.anchorPointInPoints.y + vY / magV * thumbNode.size.width;
thumbNode.position = CGPointMake(aX, aY);
}
}
}
velocity = CGPointMake(((thumbNode.position.x - self.anchorPointInPoints.x)), ((thumbNode.position.y - self.anchorPointInPoints.y)));
angularVelocity = -atan2(thumbNode.position.x - self.anchorPointInPoints.x, thumbNode.position.y - self.anchorPointInPoints.y);
[_delegate joystickMovement];
}
}