0
我正在开发一款使用加速功能的游戏。我发现了如何使我的项目的举动,但不改变其“出身”,或者更准确地说,加速计算的由来:加速,移动物品
事实上,我的形象的动作,其中心定义是这样的:
imageView.center = CGPointMake(230, 240);
正如你所看到的,我使用横向模式。但是,我希望我的图像能够“逐步”移动。我的意思是渐进的就像是在游戏中Lane Splitter:
你可以看到自行车在移动,例如,当他完全位于左侧时,该男子可以水平定向他的iPad,但是自行车没有回到屏幕中间。我不知道该怎么做,因为当我尝试一种解决方案时,我的图像会移动,但只要我的iPhone水平,就会回到中心位置。我明白为什么,但我不知道如何解决这个问题。
这是我当前的代码:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
int i = 0;
float current;
if (i == 0)
{
imageView.center = CGPointMake(230, 240);
current = 240;
i++;
}
//try to modify the origin of acceleration
imageView.center = CGPointMake(230, current - (acceleration.y*200));
current = imageView.center.y;
}
这运行得很好!感谢您的帮助=)(由于声誉较低,无法投票:/) – user2057209 2013-02-23 11:31:53