我正在尝试开发一个简单的足球游戏,包括点球,在其中我必须为从球员到球门柱的球设置动画......之前我一直在使用简单的动画,使用计时器添加到球图像的轴上,以便它从一个点移动到另一个点..但我没有想要的结果,因为动画不是那么流畅......所以我正在考虑使用游戏引擎......因为我是一个新程序员,我对游戏引擎一无所知我也找不到任何关于box2d或花栗鼠或麻雀等引擎的适当文档..我也在考虑使用UIView 动画而不是早期的动画,因为我认为这可以实现更好的动画,而无需挠头尝试在游戏引擎上工作....我不会去任何地方,所以如果有人能对此有所了解,那就太好了我的问题???
问问题
423 次
2 回答
2
使用 UIView 动画,例如:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // or whatever time
object.center=CGPointMake(object.center.x+2, object.center.y+4);
// or whatever
[UIView commitAnimations];
您还应该使用具有相同间隔的 NSTimer,以便您可以流畅地调用动画。
NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:0.3 target: self
selector:@selector(animation) userInfo: nil repeats: YES];
然后,实现方法:
- (void)animation {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // or whatever time
object.center=CGPointMake(object.center.x+5, object.center.y+7);
// or whatever
[UIView commitAnimations];
}
这应该适用于任何简单的游戏。
于 2010-11-29T22:53:42.023 回答
0
当您用 标记问题时cocos2d
,我猜您正在使用它或计划使用它。CCSprites
正如你在这个游戏中看到的那样,动画很容易https://github.com/haqu/tweejump。
在您的onEnter
实现中,只需调用 [self scheduleUpdate]
这将定期调用update:
您可以进行绘图的地方
- (void)update:(ccTime)dt {
ball_pos.x += ball_velocity.x * dt;
ball_pos.y += ball_velocity.y * dt;
ball_velocity.x += ball_acc.x * dt;
ball_velocity.y += ball_acc.y * dt;
//game logic goes here (collision, goal, ...)
ball.position = ball_position;
}
这将处理球的平稳运动。ball_pos
,ball_velocity
和ball_acc
存在vvCertex2F
。
您可能甚至不必处理加速度,只需在有人击球时给球一个冲动(即提高速度)。
您可能还需要一些阻尼来减慢球的速度。你可以通过降低每一步的速度来做到这一点
于 2013-03-19T09:21:38.300 回答