试图像线路跑步者一样编程类似的应用程序

时间:2011-09-18 01:49:18

标签: iphone objective-c ios xcode4

我是IOS和macOsx开发的新手。我有一个任务留给我一个教练,帮助我们获得iPhone开发的基础。他希望我们复制线路亚军。显然仅用于教育目的。现在她是我的问题或我有的问题,我不知道如何开始。如果你们可以向我展示任何可能对我有帮助或通过此帮助的教程。非常感谢它。

1-不知道如何生成移动的背景./ 2-我知道如何让我的png在屏幕上移动,但还是学习如何告诉他们在触摸时做些什么。 (所以跳起来我把它盖住但不是当他碰到一个物体时。

感谢所有可以提供帮助的人。

1 个答案:

答案 0 :(得分:1)

我不确定这是否是您正在寻找的答案,但对于移动背景,您可以做的是制作一个非常宽的图像,然后使用以下内容以编程方式移动该图像:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:x];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatCount:y];
imageX.transform = CGAffineTransformMakeTranslation(5,0);
[UIView commitAnimations];

这将使您的图像移动一段时间,您甚至可以根据需要将其设置为重复。

另一种方法是制作您想要创建的动画的帧,例如,您将为背景动画创建20个图像,然后使用以下内容:

imageX.animationImages = [NSArray arrayWithObjects:
 [UIImage imageNamed:@"img1.png"], //You would go all the way up to 20
 [UIImage imageNamed:@"img2.png"],
 [UIImage imageNamed:@"img3.png"],
 [UIImage imageNamed:@"img4.png"], nil];

[imageX setAnimationDuration:x];
[imageX setAnimationRepeatCount:20];
[imageX startAnimating];

要告诉玩家在触摸另一个物体时做某事,您可以使用以下内容:

if (CGRectIntersectsRect(player.frame, enemy.frame)) {
    //Collision Detected
    //Code Goes Here
}