如何在拼图游戏中replace图像

我正在做我的第一个游戏,像简单的益智游戏。

我是一个游戏程序的喵喵。

我在视图中放置了一个4图像视图,通过使用这个代码裁剪一个原始图像来为它们分配图像。

int partId = 0; for (int x=0; x<=200; x+=100) { for(int y=0; y<=200; y+=100) { CGImageRef cgImg = CGImageCreateWithImageInRect(whole.CGImage, CGRectMake(x, y, 100, 100)); UIImage* part = [UIImage imageWithCGImage:cgImg]; 

要获得图像视图位置在视图中,我正在使用此代码

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // get touch event UITouch *touch = [[event allTouches] anyObject]; CGPoint touchLocation = [touch locationInView:self.view]; NSLog(@"%f %f",touchLocation.x,touchLocation.y); 

现在,当我需要一个图像视图靠近另一个图像视图时,我需要交换他们的位置。

例如:part1在part1的place1和part1在part2的地方过来part2然后part2。

我怎么能做到这一点,任何人都可以帮助我。

这是做这个益智游戏的正确方法吗?

提前感谢你。

那么当你使用图像,你需要在你的项目中实现碰撞检测逻辑。 尝试http://apress.com/book/downloadfile/4587中的一些代码&#x3002; 它在碰撞检测方面有很好的例子,并且是免费的。

并尝试阅读本书在iphone上的游戏开发

http://apress.com/book/view/9781430225997

干杯