我正在创建一个相对复杂的动画序列。在它中,一个特定的SKSpriteNode (鲨鱼)做两次旋转。在动画的开头,它围绕某个锚点ap1旋转,然后围绕一个不同的锚点ap2旋转。如何在动画序列的中途改变锚点?
的一些初步想法:
我可以在SKAction之外,在update:循环中更改锚点。
我可以使用多个SKSpriteNode对同一个鲨鱼精灵(与它们各自的锚点),切换(隐藏/显示)雪碧节点时,我需要改变锚点。
发布于 2014-12-08 21:11:39
由于更改精灵的锚点会影响其呈现的位置,因此您可能需要进行某种调整,以防止雪碧突然移动到新的位置。有一种方法可以做到:
创建更改锚点的操作
SKAction *changeAnchorPoint = [SKAction runBlock:^{
[self updatePosition:sprite withAnchorPoint:CGPointMake(0, 0)];
}];
SKAction *rotate = [SKAction rotateByAngle:2*M_PI duration: 2];运行动作以旋转,更改锚点,并旋转
[sprite runAction:[SKAction sequence:@[rotate,changeAnchorPoint,rotate]] completion:^{
// Restore the anchor point
[self updatePosition:sprite withAnchorPoint:CGPointMake(0.5, 0.5)];
}];此方法调整精灵的位置以补偿锚点的变化
- (void) updatePosition:(SKSpriteNode *)node withAnchorPoint:(CGPoint)anchorPoint
{
CGFloat dx = (anchorPoint.x - node.anchorPoint.x) * node.size.width;
CGFloat dy = (anchorPoint.y - node.anchorPoint.y) * node.size.height;
node.position = CGPointMake(node.position.x+dx, node.position.y+dy);
node.anchorPoint = anchorPoint;
}发布于 2014-12-08 20:06:50
正如Julio Montoya所说,最简单的方法就是用方法[SKAction runBlock:myBlock]将代码“转换”为SKAction。
https://stackoverflow.com/questions/27365797
复制相似问题