Lochie Short
Aspiring developer
Profile
Posts: 16
Reg: Oct 23, 2012
Lara, Geelong, ...
1,960
09/16/13 01:00 AM (12 years ago)

Another Error in my XCode.

Hi guys, I typed in this to my XCode: //checks if tap intersects bug image.. -(BOOL)intersecting:(CGPoint)touchLocation:(UIImageView *)imageViewBug{ and it came up with this: Use of undeclared identifier 'intersecting' I was having a go at the cheat sheet on the youtube video so i can get my head around things. if you have any suggestions i would love to hear them!!! Lochie
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/16/13 01:29 AM (12 years ago)
Was there a closing bracket anywhere? -(BOOL)intersecting:(CGPoint)touchLocation:(UIImageView *)imageViewBug{ } //<----- every open bracket needs a closing bracket. If it still gives the error, you might try having that method also declared in your header (.h) file -(BOOL)intersecting:(CGPoint)touchLocation:(UIImageView *)imageViewBug; Hope this helps. Cheers! -- Smug
 
Lochie Short
Aspiring developer
Profile
Posts: 16
Reg: Oct 23, 2012
Lara, Geelong, ...
1,960
like
09/16/13 01:51 AM (12 years ago)
Thanks Smug, only it didnt help. this is what i have in my .h file: #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "BT_viewController.h" @interface BT_screen_blank : BT_viewController { UIImageView *imgViewBug; UIImageView *imgViewSplat; UIButton *buttonStart; NSTimer *gameLoopTimer; CGPoint destination; CGFloat xamt; CGFloat yamt; CGFloat speed; } @property (nonatomic, retain) UIImageView *imgViewBug; @property (nonatomic, retain) UIImageView *imgViewSplat; @property (nonatomic, retain) UIButton *buttonStart; @property (nonatomic, retain) NSTimer *timerGameLoop; @property (nonatomic) CGPoint destination; @property (nonatomic) CGFloat xamt; @property (nonatomic) CGFloat yamt; @property (nonatomic) CGFloat speed; -(void)startGame; -(void)endGame; -(void)moveBug; -(BOOL)intersecting:(CGPoint)touchLocation:(UIImageView *)imageViewBug; -(BOOL)intersecting:(CGPoint)touchLocation:(UIImageView *)imageViewBug; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; @end And this is what i have in my .m file: #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import "JSON.h" #import "BT_application.h" #import "BT_strings.h" #import "BT_viewUtilities.h" #import "BUGSPLATTER_appDelegate.h" #import "BT_item.h" #import "BT_debugger.h" #import "BT_viewControllerManager.h" #import "BT_screen_blank.h" @implementation BT_screen_blank @synthesize imgViewBug, imgViewSplat, buttonStart, timerGameLoop; @synthesize destination, xamt, yamt, speed;//viewDidLoad -(void)viewDidLoad{ [BT_debugger showIt:self theMessage:@"viewDidLoad"]; [super viewDidLoad]; //put code here that adds UI controls to the screen. } //view will appear -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [BT_debugger showIt:self theMessage:@"viewWillAppear"]; //flag this as the current screen BUGSPLATTER_appDelegate *appDelegate = (BUGSPLATTER_appDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.rootApp.currentScreenData = self.screenData; //setup navigation bar and background [BT_viewUtilities configureBackgroundAndNavBar:self theScreenData:[self screenData]]; //create an image object for the bug... UIImage *imgBug = [UIImage imageNamed:@"bug.png"]; //setup bug image view, setting it's image to the bug... imgViewBug = [[UIImageView alloc] initWithImage:imgBug]; //add bug image to screen as subView [self.view addSubview:imgViewBug]; //set the starting frame for the bug (left, top, width, height)... [imgViewBug setFrame:CGRectMake(0,0,50,50)]; //hide the bug image until the game begins... [imgViewBug setHidden:TRUE]; //add the "splat" image on top of the bug. Make it exactly the same size as the bug. //this iamge is hidden until the bug is tapped... UIImage *imgSplat = [UIImage imageNamed:@"splat.png"]; imgViewSplat = [[UIImageView alloc] initWithImage:imgSplat]; [imgViewSplat setFrame:CGRectMake(0, 0, 50, 50)]; [self.view addSubview:imgViewSplat]; [imgViewSplat setHidden:TRUE]; //create the start button... buttonStart = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [buttonStart setFrame:CGRectMake(80, 360, 160, 50)]; [buttonStart setTitle:@"Start Game" forState:UIControlStateNormal]; [buttonStart addTarget:self action:@selector(startGame) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:buttonStart]; //inti numeric values... destination = CGPointMake(0, 0); xamt = 0; yamt = 0; speed = 65; //lower number is faster } //dealloc -(void)dealloc { [super dealloc]; } //view will appear -(void):(BOOL)animated{ [super viewWillAppear:animated]; [BT_debugger showIt:self:@"viewWillAppear"]; //flag this as the current screen BUGSPLATTER_appDelegate *appDelegate = (BUGSPLATTER_appDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.rootApp.currentScreenData = self.screenData; //setup navigation bar and background [BT_viewUtilities configureBackgroundAndNavBar:self:[self screenData]]; } //start game method... -(void)startGame{ [BT_debugger showIt:self:@"startGame"]; //hide the start button... [self.buttonStart setHidden:TRUE]; //set text on start button to "restart" for next time... [buttonStart setTitle:@"Play Again" forState:UIControlStateNormal]; //show the bug image... [imgViewBug setHidden:FALSE]; //make sure the splat is hidden... [imgViewSplat setHidden:TRUE]; //random location withing the 320 / 480 screen size... destination = CGPointMake(arc4random() % 320, arc4random() % 480); //calculate steps / moving distance based on speed... xamt = ((destination.x - self.imgViewBug.center.x) / speed); yamt = ((destination.y - self.imgViewBug.center.y) / speed); //fire timer every .02 milliseconds to trigger the "moveBug" method... gameLoopTimer = [NSTimer scheduledTimerWithTimeInterval:(0.02) target:self selector:@selector(moveBug) userInfo:nil repeats: YES]; } //end game... -(void)endGame{ [BT_debugger showIt:self:@"endGame"]; //stop the timer... [gameLoopTimer invalidate]; gameLoopTimer = nil; //show the start button... [self.buttonStart setHidden:FALSE]; //hide the bug... [self.imgViewBug setHidden:TRUE]; //show the splat... [self.imgViewSplat setHidden:FALSE]; } //move bug... -(void)moveBug{ [BT_debugger showIt:self:@"moveBug"]; //tmp variables to calculate current distance... CGFloat xdist = fabs(destination.x - self.imgViewBug.center.x); CGFloat ydist = fabs(destination.y - self.imgViewBug.center.y); //if we are "close" to the destination, move the bug... if ( (xdist < 5) && (ydist < 5) ){ destination = CGPointMake(arc4random() % 320, arc4random() % 440); xamt = ((destination.x - self.imgViewBug.center.x) / speed); yamt = ((destination.y - self.imgViewBug.center.y) / speed); }else{ //keep moving if the distance is "too far"... self.imgViewBug.center = CGPointMake(self.imgViewBug.center.x + xamt, self.imgViewBug.center.y + yamt); self.imgViewSplat.center = CGPointMake(self.imgViewSplat.center.x + xamt, self.imgViewSplat.center.y + yamt); } //checks if tap intersects bug image.. -(BOOL)intersecting:(CGPoint)touchLocation:(UIImageView *)imageViewBug{ (problem lies here ^) //touch location, x and y... CGFloat x1 = touchLocation.x; CGFloat y1 = touchLocation.y; //square around bug image... CGFloat x2 = self.imgViewBug.frame.origin.x; CGFloat y2 = self.imgViewBug.frame.origin.y; CGFloat w2 = self.imgViewBug.frame.size.width; CGFloat h2 = self.imgViewBug.frame.size.height; //do they intersect? if ((x1 > x2) && (x1 < x2 + w2) && (y1 > y2) && (y1 < y2 + h2)) { return TRUE; }else{ return FALSE; } } //capture touch events... -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //touch object passed in by iOS... UITouch *touch = [[event allTouches] anyObject]; //the location of the touch on the screen... CGPoint location = [touch locationInView:self.view]; //if the touch was "on the bug", stop the bug... if ([self intersecting:location :self.imgViewBug]) { //end the game... [self endGame]; } } //dealloc -(void)dealloc { [super dealloc]; [imgViewBug release]; [imgViewSplat release]; [buttonStart release]; [timerGameLoop release]; } } @end
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/16/13 03:20 AM (12 years ago)
I get a 'warning', not an error. Unless it's colored RED, you can for the moment, disregard it. Have you watched this? It walks you through the whole process. http://www.youtube.com/watch?v=DCqIrNTusOA Cheers! -- Smug
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
09/16/13 07:21 AM (12 years ago)
Noticed in your .h file you declared the same method twice. Try taking one out.
 
Lochie Short
Aspiring developer
Profile
Posts: 16
Reg: Oct 23, 2012
Lara, Geelong, ...
1,960
like
09/16/13 10:18 PM (12 years ago)
yes it is red thanks.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.