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