【发布时间】:2010-11-23 17:15:03
【问题描述】:
我正在尝试编写游戏,但我对这个动画有点卡住了。我的屏幕上有一个水平动画的球。代码如下:
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”进行动画处理。然后,它转到由游戏对象设置的正确值。有人可以帮我解决这个问题吗?
【问题讨论】:
-
使用 cocos2d?我发现它比 CA 容易得多。
-
我喜欢 cocos2D,但我认为我可以用 CALayers 以一种不错的方式开发它。真快,后面有openGLES绘图。
标签: iphone calayer cabasicanimation caanimation