我有一个Spritekit游戏和一个SKSpriteNode(mapContainer),它是地图,而该地图位于另一个SKSpriteNode(rightCon)中,它是它的容器。当挤入/缩小时我想在地图上放大/缩小。
我已经在网上找到了代码并设法获得了似乎有用的东西,但这不太对。
问题在于,一旦我开始捏它就跳了一点(我的意思是,地图明显地移动位置而不是平稳地移动),然后它平滑地放大/缩小到捏。而且我不确定为什么。
- (void)rightConPTZ:(UIPinchGestureRecognizer *)recognizer {
CGPoint touchLocation = [recognizer locationInView:recognizer.view];
touchLocation = [self convertPointFromView:touchLocation];
CGPoint pointInMap = [rightCon convertPoint:touchLocation fromNode:self];
if (recognizer.state == UIGestureRecognizerStateChanged) {
float scale = recognizer.scale-lastScale;
mapContainer.xScale += scale;
mapContainer.yScale += scale;
float centerX = 0;
float centerY = 0;
float offsetToCenterX = centerX-pointInMap.x;
float offsetToCenterY = centerY-pointInMap.y;
float multiX = offsetToCenterX*mapContainer.xScale;
float multiY = offsetToCenterY*mapContainer.xScale; //xscale & yscale are the same (and always will be)
float zoomInFactor = 2;
float scaleDiff = (zoomInFactor - mapContainer.xScale) / (zoomInFactor - 1.0f);
float multiX2 = offsetToCenterX*scaleDiff;
float multiY2 = offsetToCenterY*scaleDiff;
float subX = multiX-multiX2;
float subY = multiY-multiY2;
mapContainer.position = CGPointMake(subX, subY);
lastScale = recognizer.scale;
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
lastScale = 1.0;
}
}
任何人都可以看到问题可能是什么?在代码中是否存在错误,或者我(我怀疑)是否在这个等式中留下了一些重要的部分,以便平滑地缩放到夹点?