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.
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
精彩评论