如何使用CABasicAnimation水平移动球并将球停在正确的位置
我正在尝试写一个游戏,我对这个动画有点困惑。我有一个在我的屏幕上水平动画的球。这是代码:
CABasicAnimation *horizontalBallAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
[horizontalBallAnimation setFromValue:[NSValue valueWithCGPoint:CGPointMake(50.0, 300.0 )]];
[horizontalBallAnimation setToValue:[NSValue valueWithCGPoint:CGPointMake(220.0, 300.0 )]];
horizontalBallAnimation.delegate = self;
horizontalBallAnimation.repeatCount = 1e100f;
//horizontalBallAnimation.autoreverses = YES;
horizontalBallAnimation.duration = 2.0;
[gameBallLayer addAnimation:horizontalBallAnimation forKey:@"horizontalBallAnimation"];
这很有效。然而我的问题是当我停止动画时 - 只需点击屏幕 - 球就可以到达正确的位置;
[gameLogic ballGameObject].x = [[[gameBallLayer presentationLayer] valueForKeyPath:@"position.x"] doubleValue];
[gameLogic ballGameObject].y = [[[gameBallLayer presentationLayer] valueForKeyPath:@"position.y"] doubleValue];
首先动画到horizontalBallAnimation的“ToValue”。然后,它将转到gameObject设置的正确值。有人可以帮我这个吗?
没有找到相关结果
已邀请:
1 个回复
社攻取墟槽