Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
777 views
in Technique[技术] by (71.8m points)

iphone - how to replace images in puzzle game

i am doing my first game like simple puzzle game.

i an mew to gaming program.

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.

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.

Thank u in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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

Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...