Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Well to start off, THANK YOU, all of you. And to be honest the college class I am in, I kinda jumped into before I was ready. I should of taken some more programming courses (I just have Fundamentals of C++ and C++ One under my belt), so now instead of doing text programs (like I probly should be working on) I am trying to build a game. And right now its either, build the game or fail the course, and I really don't want to fail and I figure I'll learn a lot under pressure. Heres my code:

GameViewController.h

Code:
//  Created by Brandon on 10/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "TransformView.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>


@interface GameViewController : UIViewController { 

    IBOutlet UIImageView *objCircleBlue; 
	IBOutlet UIImageView *objCircleBlueHole;
	IBOutlet UIImageView *objCircleRed;
	
}



@property (nonatomic, retain) 	IBOutlet UIImageView *objCircleBlue; 
@property (nonatomic, retain)	IBOutlet UIImageView *objCircleBlueHole;
@property (nonatomic, retain)	IBOutlet UIImageView *objCircleRed;



@end

GameViewController.m


Code:
//  Created by Brandon on 10/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "GameViewController.h"


@implementation GameViewController

@synthesize objCircleBlue, objCircleBlueHole, objCircleRed;
	
	


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName: (NSString *)nibNameOrNil bundle: (NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];

	NSError *error;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SpaceBrandon.mp3"];
	
	NSFileManager *fileManager = [NSFileManager defaultManager];
	
	if(![fileManager fileExistsAtPath: path])
	{
		NSString *bundle = [[NSBundle mainBundle] pathForResource:@"" ofType:@"mp3"];
		[fileManager copyItemAtPath:bundle toPath: path error:&error];
	}
	
	//UIAlertView *alertBreak = [[UIAlertView alloc] initWithTitle:@"SoundPath" message: path delegate: nil cancelButtonTitle: @"OK" otherButtonTitles:nil]; [alertBreak show]; [alertBreak release];
	
	AVAudioPlayer *audioPlayer;

	//NSString *Path = [[NSBundle mainBundle] pathForResource:@"SpaceBrandon" ofType@"mp3"]; 
	
	audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
	//audioPlayer.numberOfLoops = -1;
	
	
					[audioPlayer play];
	
	
	
	
	
	//TransformView* theTouchView = [[TransformView alloc] initWithImage:[UIImage imageNamed:@"Circle6.png"]];
	//[theTouchView setFrame:CGRectMake(110, 180, [theTouchView frame].size.width, [theTouchView frame].size.height)];
	//[[self view] addSubview:theTouchView];
	//[theTouchView release];
	
} 
	



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return YES;
}

- (void)didReceiveMemoryWarning 
{
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload 
{
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc 
{
		
	[super dealloc];

}





@end


The next set is where my "touches moved" and my attempt at collision is. The touches moved is based on a lesson found in iPhone and iPad Apps for Absolute Beginners by Dr. Rory Lewis

TransformView.h


Code:
//  Created by Brandon on 11/14/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>


@interface TransformView : UIImageView 
{
	UITouch* firstTouch;
	UITouch* secondTouch;
	
    IBOutlet UIImageView *objCircleBlue; 
	IBOutlet UIImageView *objCircleBlueHole;
	IBOutlet UIImageView *objCircleRed;


	
}



@property (nonatomic, retain) 	IBOutlet UIImageView *objCircleBlue; 
@property (nonatomic, retain)	IBOutlet UIImageView *objCircleBlueHole;
@property (nonatomic, retain)	IBOutlet UIImageView *objCircleRed;



- (float) angleBetweenThisPoint:(CGPoint)firstPoint  andThisPoint:(CGPoint)secondPoint;
- (float) distanceBetweenThisPoint:(CGPoint)firstPoint  andThisPoint:(CGPoint)secondPoint;


@end


TransformView.m


Code:
//  Created by Brandon on 11/14/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "TransformView.h"

@implementation TransformView
@synthesize objCircleBlue, objCircleBlueHole, objCircleRed;

- (id) initWithImage:(UIImage *)image
{
	if (self = [super initWithImage:image])
	{
		[self setUserInteractionEnabled:YES];
		[self setMultipleTouchEnabled:YES];
	}
	
	return self;
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	//Single touch
	if ([touches count] == 1)
	{
		if (!firstTouch)
		{
			firstTouch = [[touches anyObject] retain];
		}
		else if (!secondTouch)
		{
			secondTouch = [[touches anyObject] retain];
		}
	}
	
	//Multiple touch
	if ([touches count] == 2)
	{
		NSArray* theTouches = [touches allObjects];
		[firstTouch release];
		[secondTouch release];
		firstTouch = nil;
		secondTouch = nil;
		firstTouch = [[theTouches objectAtIndex:0] retain];
		secondTouch = [[theTouches objectAtIndex:1] retain];
	}
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	if ([touches count] == 1)
	{
		CGPoint newTouch = [[touches anyObject] locationInView:[self superview]];
		CGPoint lastTouch = [[touches anyObject] previousLocationInView:[self superview]];
		
		float xDif = newTouch.x - lastTouch.x;
		float yDif = newTouch.y - lastTouch.y;
		
		CGAffineTransform translate = CGAffineTransformMakeTranslation(xDif, yDif);
		[self setTransform: CGAffineTransformConcat([self transform], translate)];
	}
	else if ([touches count] == 2 && firstTouch && secondTouch)
	{
		//Rotate
		float newAngle = [self angleBetweenThisPoint:[firstTouch locationInView:[self superview]]
										andThisPoint:[secondTouch locationInView:[self superview]]];
		float oldAngle = [self angleBetweenThisPoint:[firstTouch previousLocationInView:[self superview]]
										andThisPoint:[secondTouch previousLocationInView:[self superview]]];
		
		CGAffineTransform rotation = CGAffineTransformMakeRotation(oldAngle - newAngle);
		
		[self setTransform: CGAffineTransformConcat([self transform], rotation)];
		
		//Scale
		float newDistance = [self distanceBetweenThisPoint:[firstTouch locationInView:[self superview]]
											  andThisPoint:[secondTouch locationInView:[self superview]]];
		float oldDistance = [self distanceBetweenThisPoint:[firstTouch previousLocationInView:[self superview]]
											  andThisPoint:[secondTouch previousLocationInView:[self superview]]];
		
		float ratio = newDistance / oldDistance;
		
		CGAffineTransform scale = CGAffineTransformMakeScale(ratio, ratio);
		[self setTransform: CGAffineTransformConcat([self transform], scale)];
	}
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
	[self touchesEnded:touches withEvent:event];
}

- (float) distanceBetweenThisPoint:(CGPoint)firstPoint  andThisPoint:(CGPoint)secondPoint
{
	float xDif = firstPoint.x - secondPoint.x;
	float yDif = firstPoint.y - secondPoint.y;
	
	float dist = ((xDif * xDif) + (yDif * yDif));
	
	return sqrt(dist);
}

- (float) angleBetweenThisPoint:(CGPoint)firstPoint  andThisPoint:(CGPoint)secondPoint
{
	float xDif = firstPoint.x - secondPoint.x;
	float yDif = firstPoint.y - secondPoint.y;
	
	return atan2(xDif, yDif);
}

// Check Position Attempts 
/*
// No Error here, just doesn't work. 
 
 - (void)CheckPosition{
if (objCircleBlue.center.x && objCircleBlue.center.y == objCircleBlueHole.center.x && objCircleBlueHole.center.y)
{
	
	UIAlertView *playerWin = [[UIAlertView alloc] initWithTitle:@"You Win" message:@"Yeahh you won" delegate:nil cancelButtonTitle:@"OKAY!" otherButtonTitles:nil];
	[playerWin show];
	
}
}
*/ 
/* ERROR
- (void)CheckPosition{
	if (objCircleBlue.x && objCircleBlue.y == objCircleBlueHole.x && objCircleBlueHole.y) // Request for member 'x' in something not a structure or union
	{
		
		UIAlertView *playerWin = [[UIAlertView alloc] initWithTitle:@"You Win" message:@"Yeahh you won" delegate:nil cancelButtonTitle:@"OKAY!" otherButtonTitles:nil];
		[playerWin show];
		
	}
}
 */

- (void)CheckPosition{
	if (objCircleBlue.center.x == 15) // A friend suggested to try that to see if my win condition even works, NSLog didn't report it a win.
	{
		
		UIAlertView *playerWin = [[UIAlertView alloc] initWithTitle:@"You Win" message:@"Yeahh you won" delegate:nil cancelButtonTitle:@"OKAY!" otherButtonTitles:nil];
		[playerWin show];
		NSLog(@" WIN");
	}
}

@end

Heres what I do know. I know that doing the .center.x and .center.y is a bad choice since that point alone is the size of a pixel so the player would have to be ridiculously accurate for it to work. I know that I should use an "area" of some sort (a rectangle most likely) to write a condition if the object is within a certain area, then win.

Heres what I don't know. I don't know if my win condition even works, it doesn't give me an error but I haven't seen it execute. It hasn't executed either due to it not working, or do to my condition statement to be wrong. One or the other is written improperly maybe both.

A little bit about the kind of game I am trying to accomplish. Its a little kids game, where I want to do basic things, like fitting objects in the right spots like a puzzle piece. Which is why I need to figure out a coordinate event of some sort. And the reason why I also included rotating and scaling is because later in the game for a "harder" difficulty I want the player to stretch or shrink the image to a certain size or rotate it to a certain degree to win. Its a very basic game I and my fellow students are trying to execute. Our coding team is myself and 2 other kids, and were all about as good as each other. The books I have and use are, Programming in Objective C 2.0 by Stephen Kochan and Learning iPhone Game Programming by Michael Daley. I was borrowing the Rory Lewis book from a friend. Thanks for you're help, I am looking through the books trying to come up with something. Their isn't a tutor at school for iPhone development but a friend told me about here. Between advice here, the books, self determination, I am sure I will get it done, I won't give up :)
 
Last edited by a moderator:
Heres what I don't know. I don't know if my win condition even works, it doesn't give me an error but I haven't seen it execute. It hasn't executed either due to it not working, or do to my condition statement to be wrong. One or the other is written improperly maybe both.

This line will nearly always be false, and not be true when you expect. The order of operations changes it to something you don't expect. First the == is evaluated. Then the &&'s are evaluated.

Code:
if (Object1.center.x && Object1.center.y == Object2.center.x && Object2.center.y){

It evaluates like this:
First Object1.center.y and Object2.center.x are compared. Since you are mixing up the x and y, that will nearly always be false, even if the objects are in exactly the same position.

The next part to be evaluated is Object1.center.y && false. The "false" is the result of the first comparison. So this && operation can never be true.

Lastly, you get false && Object2.center.y, which again will always be false.


I shouldn't give you the answer, but here goes:
Code:
if (Object1.center.y >= Object2.center.y - 16 && 
Object1.center.y <= Object2.center.y + 16 && 
Object1.center.x >= Object2.center.x -16 && 
Object1.center.x <= Object2.center.x + 16) {

The value of 16 defines an area larger than 1 pixel. Change it to match the size of your images. You really should walk through that and understand how it works. Google "order of operations in c" and make sure you evaluate it correctly to see how it works.

Edit: looking deeper at your code, where is "CheckPosition" called? If it's not called, it won't evaluate, whether its right or wrong. Maybe take your friends suggestion a step further. Get rid of the if statement altogether, and just have an NSLog. Maybe touchesEnded: would be a good spot? Are you able to move the circle around the screen?
 
Last edited:
Thanks a lot, yeah I'm going to look through it and actually understand it and google order of operations. I'm not trying to squeeze by in this class, I want to understand, I want to be a programmer. Its just a real do-or-die situation, if it was a programming class I'd be more relaxed and ask a lot of questions in class (but that just isn't the case in this class). And yes my circle does move around on screen =D thanks for your help, I am going to fix up my mistakes right now.
 
Well I have a new problem, no matter where I drop the image it is always outputting it as a win.


Code:
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	
	if (objCircleBlue.center.x == objCircleBlueHole.center.x) 
	{
		NSLog(@"WIN");
	}
		else {
			NSLog(@"Not there");}
		
}

I did do it the way you suggested whl99 but I stripped it down to just this to make it easier to read. So for some reason, the program thinks these two points are always equal. Even when there obviously not.
 
Last edited by a moderator:
Okay after kicking around a few new ideas, I came up with something that is kinda working, kinda not working. If anybody here can lend a hand I'd appreciate it.

First, I went into interface builder and erased the whole board. And now I added the objects strictly through code alone. Heres what my LearningBoxViewController.h looks like

Code:
#import <UIKit/UIKit.h>
#import "TransformView.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>


@interface LearningBoxViewController : UIViewController { 

	
}

 @end

this is what my LearningBoxViewController.m looks like

//
//  LearningBoxViewController.m
//  LearningBox
//
//  Created by Brandon on 10/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "LearningBoxViewController.h"


@implementation LearningBoxViewController

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];

	NSError *error;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SpaceBrandon.mp3"];
	
	NSFileManager *fileManager = [NSFileManager defaultManager];
	
	if(![fileManager fileExistsAtPath: path])
	{
		NSString *bundle = [[NSBundle mainBundle] pathForResource:@"" ofType:@"mp3"];
		[fileManager copyItemAtPath:bundle toPath: path error:&error];
	}
	
	//UIAlertView *alertBreak = [[UIAlertView alloc] initWithTitle:@"SoundPath" message: path delegate: nil cancelButtonTitle: @"OK" otherButtonTitles:nil]; [alertBreak show]; [alertBreak release];
	
	AVAudioPlayer *audioPlayer;

	//NSString *Path = [[NSBundle mainBundle] pathForResource:@"SpaceBrandon" ofType@"mp3"]; 
	
	audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
	//audioPlayer.numberOfLoops = -1;
	
	
					[audioPlayer play];
	
	

	
	TransformView* circleG = [[TransformView alloc] initWithImage:[UIImage imageNamed:@"circleG.png"]];
	[circleG setFrame:CGRectMake(20, 20, [circleG frame].size.width, [circleG frame].size.height)];
	[[self view] addSubview:circleG];
	[circleG release];
	
	
	
	
	
	TransformView* circleB = [[TransformView alloc] initWithImage:[UIImage imageNamed:@"circleB.png"]];
	[circleB setFrame:CGRectMake(25, 20, [circleB frame].size.width, [circleB frame].size.height)];
	[[self view] addSubview:circleB];
	[circleB release];
	
		
		/*
		if(CGRectIntersectsRect(circleB, circleG)){
			NSLog(@"Win");
		}
		else{
			NSLog(@"Not there");
		}
		*/
	
	if(circleB.center.x == circleG.center.x)
	{
		NSLog(@"Win");
	}
	else
	{
		NSLog(@"Not There");
	}


} 








// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return YES;
}

- (void)didReceiveMemoryWarning 
{
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload 
{
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}




- (void)dealloc 
{
		
	[super dealloc];

}

@end

Now when I set the code for them to appear directly on top of each other. NSLog reports a Win. When I set the code for them NOT to appear on each other, the NSLog reports Not There. However, considering this is just called when the game loads and never calls again, makes it useless. SO in my Transformview.m

Code:
//
//  TransformView.m
//
//  Created by Brandon on 11/14/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//


#import "TransformView.h"
#import "LearningBoxViewController.h"




@implementation TransformView


- (id) initWithImage:(UIImage *)image
{
	
	
	if (self = [super initWithImage:image])
	{
		[self setUserInteractionEnabled:YES];
		[self setMultipleTouchEnabled:YES];
	}
	
	return self;
}


- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	//Single touch
	if ([touches count] == 1)
	{
		if (!firstTouch)
		{
			firstTouch = [[touches anyObject] retain];
		}
		else if (!secondTouch)
		{
			secondTouch = [[touches anyObject] retain];
		}
	}
	
	//Multiple touch
	if ([touches count] == 2)
	{
		NSArray* theTouches = [touches allObjects];
		[firstTouch release];
		[secondTouch release];
		firstTouch = nil;
		secondTouch = nil;
		firstTouch = [[theTouches objectAtIndex:0] retain];
		secondTouch = [[theTouches objectAtIndex:1] retain];
	}
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	if ([touches count] == 1)
	{
		CGPoint newTouch = [[touches anyObject] locationInView:[self superview]];
		CGPoint lastTouch = [[touches anyObject] previousLocationInView:[self superview]];
		
		float xDif = newTouch.x - lastTouch.x;
		float yDif = newTouch.y - lastTouch.y;
		
		CGAffineTransform translate = CGAffineTransformMakeTranslation(xDif, yDif);
		[self setTransform: CGAffineTransformConcat([self transform], translate)];
	}
	else if ([touches count] == 2 && firstTouch && secondTouch)
	{
		//Rotate
		float newAngle = [self angleBetweenThisPoint:[firstTouch locationInView:[self superview]]
										andThisPoint:[secondTouch locationInView:[self superview]]];
		float oldAngle = [self angleBetweenThisPoint:[firstTouch previousLocationInView:[self superview]]
										andThisPoint:[secondTouch previousLocationInView:[self superview]]];
		
		CGAffineTransform rotation = CGAffineTransformMakeRotation(oldAngle - newAngle);
		
		[self setTransform: CGAffineTransformConcat([self transform], rotation)];
		
		//Scale
		float newDistance = [self distanceBetweenThisPoint:[firstTouch locationInView:[self superview]]
											  andThisPoint:[secondTouch locationInView:[self superview]]];
		float oldDistance = [self distanceBetweenThisPoint:[firstTouch previousLocationInView:[self superview]]
											  andThisPoint:[secondTouch previousLocationInView:[self superview]]];
		
		float ratio = newDistance / oldDistance;
		
		CGAffineTransform scale = CGAffineTransformMakeScale(ratio, ratio);
		[self setTransform: CGAffineTransformConcat([self transform], scale)];
	}
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
	{
		
		
	}			  



- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
	[self touchesEnded:touches withEvent:event];	

}

- (float) distanceBetweenThisPoint:(CGPoint)firstPoint  andThisPoint:(CGPoint)secondPoint
{
	float xDif = firstPoint.x - secondPoint.x;
	float yDif = firstPoint.y - secondPoint.y;
	
	float dist = ((xDif * xDif) + (yDif * yDif));
	
	return sqrt(dist);
}

- (float) angleBetweenThisPoint:(CGPoint)firstPoint  andThisPoint:(CGPoint)secondPoint
{
	float xDif = firstPoint.x - secondPoint.x;
	float yDif = firstPoint.y - secondPoint.y;
	
	return atan2(xDif, yDif);
}


@end

I should stick the if statement inside the touches ended function (so it calls it every time player stops touching the piece). However, I get an error stating the circleB and circleG are undeclared. So how would I make them declared under the transformview.m ? Also worth mentioning I tried doing the if(CGRectIntersectsRect(circleB, circleG)) statement but I get an error back that states... Incompatible type of argument 1 of 'CGRectIntersectsRect' how would I fix that? I think it would be better to use that if its possible as the .center.x idea would have to be too precise for the player to execute.

So recap, what I want to do, is have my if statement called under the Transformview's touches ended function, though I need to know how to declare my circleB and circleG in there for that to be possible. I have tried #import LearningBoxViewController.m and I've tried @synthesize circleB, circleG; and neither worked. Not sure what to do.
 
Last edited:
No I didn't try that, but I did just now since you suggested. What happens there is, if I put it inside the viewDidLoad function it says touchesEnded undeclared. If I put it outside the viewDidLoad it says circleB undeclared. I'll check out that link you posted now
 
No I didn't try that, but I did just now since you suggested. What happens there is, if I put it inside the viewDidLoad function it says touchesEnded undeclared. If I put it outside the viewDidLoad it says circleB undeclared. I'll check out that link you posted now

I have your code working, you are close, but have several errors.

First, touchesEnded goes outside of viewDidLoad. touchesEnded is a method, as is viewDidLoad. Your circles are declared in viewDidLoad, so they are inaccessible to anything outside of that scope. To fix that, declare them in LearningBoxViewController.h

Code:
@interface LearningBoxViewController : UIViewController {
	TransformView* circleG;
	TransformView* circleB;
}

Then, remove the declaration in viewDidLoad.

Code:
	circleG = [[TransformView alloc] initWithImage:[UIImage imageNamed:@"circleG.png"]];
	[circleG setFrame:CGRectMake(20, 20, [circleG frame].size.width, [circleG frame].size.height)];

touches ended still won't be called in LearningBoxViewController because it is being handled earlier in the responder chain. Delete touchesEnded from TransformView. Don't leave it empty- delete it.

This throws an error about incompatible types:
Code:
 if(CGRectIntersectsRect(circleB, circleG))

You need to use circleB.frame

Code:
 if(CGRectIntersectsRect(circleB.frame, circleG.frame))

I was stumped for a while on why this didn't work:
Code:
NSLog(@"CircleB.center.x = %f",circleB.center.x);
	NSLog(@"CircleG.center.x = %f",circleG.center.x);
	
	if(circleB.center.x == circleG.center.x)
	{
		NSLog(@"Win");
	}
	else
	{
		NSLog(@"Not There");
	}

It actually DOES work. If you set the two circles to the same position in the beginning, it will show a win. If the are different it will show a loss. But when you move the circles, the x and y values don't change. That is because of the way you are moving them in touchesMoved. (did you copy that from a book?)

I changed touchesMoved to this:


Code:
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	CGPoint newTouch = [[touches anyObject] locationInView:[self superview]];
	self.center = newTouch;

}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.