如何在益智游戏中替换图像 [英] how to replace images in puzzle game

查看:156
本文介绍了如何在益智游戏中替换图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am doing my first game like simple puzzle game.

我对游戏程序的喵喵。

我在视图中放置一个4图像视图,通过使用此代码裁剪一个原始图像将图像分配给它们。

i place a 4 image view in the view assign images to them by cropping one original image using this code.

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];

获取视图中的图像视图位置我正在使用此代码

to get the image view position in the view i am using this code

- (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);

现在我需要的是当一个图像视图接近另一个图像视图然后我需要交换他们的头寸。

Now what i need to when ever one image view comes near to the another image view then i need to exchange their positions.

例如:part1来自part2,然后part2位于part1的place1和part1位于part2的位置。

eg: part1 come over part2 then part2 in the place1 of part one and part1 in the place of part2.

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

How can i done this can any one please help me.

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

Is this is correct approach to do this puzzle game.

提前感谢你。

推荐答案

当你使用图像时,你需要实现碰撞项目中的检测逻辑。尝试 http://apress.com/book/downloadfile/4587 中的一些代码。它有很好的碰撞检测示例,它是免费的。

Well as you are using images you need to implement collision detection logic in your project. try some of the codes in http://apress.com/book/downloadfile/4587. it has very good examples on collision detection and it is free.

并尝试阅读本书以便在iphone上进行游戏开发

and also try to read this book for game development on iphone

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

干杯

这篇关于如何在益智游戏中替换图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆