 |
 |
|
 |
04-22-2009, 12:16 AM
|
#1 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 10
|
Photo hunt game: high level design help
I'm in the beginning stages of creating a photo hunt/spot the difference game. The type where players must pick out differences between two similar photographs.
As a proof of concept, I created an incredibly crude prototype using almost entirely interface builder. I have 2 images on screen, with a bunch of nearly invisible buttons placed over differences in the pictures. When one of the invisible buttons is pressed, an alert pops up saying "You found a difference."
My question is from a design perspective, is there a better method of implementing this game programmatically? There must be a better way than littering the screen with invisible buttons and having 20 nibs for 20 pictures.
Since these photo hunt games are so popular, there must be some "standard" method of design/implementation i don't know of.
|
|
|
04-22-2009, 01:03 AM
|
#2 (permalink)
|
|
FasterThanMonkeys.com
iPhone Dev SDK Supporter
Join Date: Mar 2009
Location: Southern California
Posts: 521
|
Probably just using a single NIB with an image, and using touch events to capture x/y coordinates would be the simplest design. Each image would have rectangles associated with it that represent the differences. Each time a user touches the screen, the x/y location would be compared to the list of rectangles.
Just out of curiosity... is there something that is going to make your photo hunt unique? Or is it just a learning experience for you?
Last edited by ftm; 04-22-2009 at 03:13 AM.
|
|
|
04-22-2009, 01:15 AM
|
#3 (permalink)
|
|
Pro. Game Developer
iPhone Dev SDK Supporter
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 1,415
|
Quote:
Originally Posted by ftm
Probably just using a single NIB with an image, and using touch events to capture x/y coordinates would be the simplest design. Each image would have rectangles associated with it that represent the differences. Each time a user touches the screen, the x/y location would be compared to the list of images.
Just out of curiosity... is there something that is going to make your photo hunt unique? Or is it just a learning experience for you?
|
I (not the OP) was thinking of doing one of these as a starter project just to get something onto the App Store, but eventually decided against it and started focusing on my "real" project. Anyways, the architecture you describe is essentially what I was thinking -- I think. Each "puzzle" would have a dataset consisting of an image (prebuilt with the different left and right side images) and a number of (x,y) positions. During game play, any touch position would be compared against all of the positions (adjusted for both the left and right panes). Any touch within a predefined radius of any of the positions would register as a correct guess, and that position would be marked as such, etc. etc. Pretty simple and straightforward implementation.
|
|
|
04-22-2009, 04:30 PM
|
#4 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 10
|
Thanks for the quick response.
I'm using it primarily as a learning experience. Thus far the only saving/loading of information I've dealt with is using NSUserDefaults to keep track of high score data.
So if I understand both of your implementation suggestions correctly, I should have all my static images (ie: jpgs) stored in my project resources folder, as well as a text file of some sort (plist?) to save the x,y coordinates of the difference points.
Then I associate each picture to an entry in my text file.
ie: associate "1.jpg" to "entry 1" in the text file. With each entry formatted something like "[entry number:(x1 coordinate, y1 coordinate), ... (xN coordinate, yN coordinate)]"
|
|
|
04-22-2009, 05:56 PM
|
#5 (permalink)
|
|
smithdale87's boss.
Join Date: Nov 2008
Location: Memphis, TN
Posts: 267
|
Quote:
Originally Posted by tarenar
Thanks for the quick response.
I'm using it primarily as a learning experience. Thus far the only saving/loading of information I've dealt with is using NSUserDefaults to keep track of high score data.
So if I understand both of your implementation suggestions correctly, I should have all my static images (ie: jpgs) stored in my project resources folder, as well as a text file of some sort (plist?) to save the x,y coordinates of the difference points.
Then I associate each picture to an entry in my text file.
ie: associate "1.jpg" to "entry 1" in the text file. With each entry formatted something like "[entry number  x1 coordinate, y1 coordinate), ... (xN coordinate, yN coordinate)]"
|
You got it!! Let us know how it turns out.
|
|
|
04-23-2009, 04:38 AM
|
#6 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 10
|
I've structured my plist as follows
Code:
Array (represents all pictures)
Array1 (represents picture)
Dictionary1 (2 coordinates for difference in image)
Number1 (x1 coordinate)
Number2 (y1 coordinate)
Number3 (x2 coordinate)
Number4 (y2 coordinate)
Number5 (found variable set to 1 if this difference found)
...
ArrayN
Dictionary1
Number1
Number2
Number3
Number4
Number5
An outer array represents all of my pictures, while the inner array represents an individual picture. Each of the 5 dictionaries in the inner array holds coordinates for differences in the pictures. The found variable is set to 1 when a difference for this image is found.
I detect when the user touches each point with the following code, shortened for brevity:
Code:
//pseudo code for brevity
-(void)touchesEnded:
get touch location
for (each dictionary in the picture array) {
if (player touches one of the points) {
set the found variable for this point to 1/YES
}
}
In the if statement, when a difference is successfully found, I set the "found" variable in my dictionary to "1" to indicate that I found a difference.
In the simulator everything works fine. But when I load the app onto my phone, and tap a difference point, the screen freezes. The only way to quit is to stop it within Xcode. Using the debugger, I pinpointed the crash to the line of code "[currentDiff setObject:tempBool forKey:@"found"];" below. Specifically the tempBool variable.
Code:
//2 rects always point to 1 difference. if finger in one of the two rects, found a difference
if (((CGRectContainsPoint(leftRect, location)) || CGRectContainsPoint(rightRect, location)) && (found == 0))
{
//now that we've found a difference, update local copy of the picture data and set its found flag to 1(true)
NSNumber *tempFound = [[NSNumber alloc] initWithInt:1];
[currentDiff setObject:tempFound forKey:@"found"]; //crashing game on iphone
[tempFound release];
[localCopyPic replaceObjectAtIndex:i withObject:currentDiff];
}
Why does this code work in the simulator but not on my phone?
|
|
|
04-23-2009, 04:10 PM
|
#7 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 10
|
To avoid replacing the "found" variable in my dictionary, I simply deleted the dictionary once a difference was found. This approach appears to work.
Still, it's odd how the previous implementation worked in the simulator but not the phone.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 407 |
| 31 members and 376 guests |
| AlexTheMighty, aniuco, asimrs, Berko, BSDimwit, divya, dljeffery, firearasi, georgeburns, helen412, ImpresionesWeb, iphonegamedeveloper, iTrackiGiveaway, Jayakrishnan9704, jaywright00, Julie, JZhang273, kmadhukishore, linkmx, martino, mmilo, Mrajpsteve, orange gold, panpan, scotopia, sharhelia, SimpleSDK, skunk, smljackson, smrtital, UconnAggie |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,074
Threads: 38,856
Posts: 170,469
Top Poster: smasher (2,563)
|
| Welcome to our newest member, panpan |
|