我已经在我的 SKScene 上实现了缩放/捏合,并在此线程中选择了答案:
我现在正试图让英雄角色在捏合或缩放动作期间保持居中(平滑),因为如果我不这样做,heroNode 将很快从屏幕上消失。我有一个 centerHero 方法,我可以在需要时调用它,而且效果很好,但是当我在夹点处理程序结束时调用此方法时,效果非常非常生涩。这是捏处理程序:
- (void)handlePinch:(UIPinchGestureRecognizer *) recognizer
{
[map runAction:[SKAction scaleBy:recognizer.scale duration:0]];
recognizer.scale = 1;
// While zooming/pinching, make sure hero is centered:
[self centerHero];
}
这是中心英雄方法:
- (void)centerHero
{
CGFloat centerX = self.view.bounds.size.width/2;
CGFloat centerY = self.view.bounds.size.height/2;
CGFloat heroX = [self.heroNode parent].position.x;
CGFloat heroY = [self.heroNode parent].position.y;
CGPoint heroPoint = CGPointMake(heroX, heroY);
CGPoint newHeroPoint = [self convertPoint:heroPoint fromNode:map];
CGFloat newHeroX = newHeroPoint.x;
CGFloat newHeroY = newHeroPoint.y;
CGFloat xDiff = centerX - newHeroX;
CGFloat yDiff = centerY - newHeroY;
SKAction *moveBy = [SKAction moveByX:xDiff y:yDiff duration:5];
[map runAction:moveBy];
}
关于如何使这种“自动居中”顺利进行的任何建议?