Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2009, 06:54 PM   #1 (permalink)
Registered Member
 
AppStoreMod's Avatar
 
Join Date: Jul 2009
Location: Sacramento,CA
Posts: 90
Send a message via Skype™ to AppStoreMod
Default UIAlertView Popping Up A Bunch Of Times In The if(CGRectIntersectsRect) Code ?

Hey guys when I am using the. if CGRectIntersectsRect(image5.frame,image2.frame)) in my Xcode project. I have an UIAlertView right in the code. At times my app will start making the alert pop up over and over again and sometimes it works. Its when two images touch its suppose to have this code come up. I have it formatted like this. I also have a -(void)checkCollision in there. See any errors please help me. Here you go:

Quote:
-(void)checkCollision {



if( CGRectIntersectsRect(image1.frame,image2.frame))
{
[myTwitter setHidden:NO];

CGRect frame = [image1 frame];
frame.origin.x = 135.0f;
frame.origin.y = 35.0f;
[image1 setFrame:frame];

CGRect frame3 = [image3 frame];
frame3.origin.x = 135.0f;
frame3.origin.y = 35.0f;
[image1 setFrame:frame3];

CGRect frame4 = [image4 frame];
frame4.origin.x = 135.0f;
frame4.origin.y = 35.0f;
[image1 setFrame:frame4];

CGRect frame2 = [image2 frame];
frame2.origin.x = 138.0f;
frame2.origin.y = 343.0f;
[image2 setFrame:frame2];

pos = CGPointMake(0.0,0.0);
pos2 = CGPointMake(0.0,0.0);
pos3 = CGPointMake(0.0,0.0);
pos4 = CGPointMake(0.0,0.0);

[image1 setHidden:YES];
[image4 setHidden:YES];
[image5 setHidden:YES];
[backLabel setHidden:NO];


UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"You Lose" message:[NSString stringWithFormat:@"The Nail hit you and you popped. You were alive for %d seconds. Keep playing and see if you can beat that!", mainInt] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alertView show];
[alertView release];
[randomMain invalidate];
randomMain = nil;

UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"BaloonPopped1" ofType:@"png"]];
[image2 setImage:img];

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Popped", CFSTR("mp3"), NULL);
if (soundFileURLRef) {
}
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);

}

if( CGRectIntersectsRect(image1.frame,image3.frame))
{

CGRect frame = [image1 frame];
frame.origin.x = 1 + arc4random() % 300;
frame.origin.y = -20.0f;
[image1 setFrame:frame];


}
AppStoreMod is offline   Reply With Quote
Old 09-11-2009, 11:47 PM   #2 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 109
Default

How often is your check collision method being called? If you have a timer that checks it every second or so, the object colliding with the other object could still be intersecting, therefore, the method gets called multiple times
davidlansalot is offline   Reply With Quote
Old 09-12-2009, 12:03 AM   #3 (permalink)
Registered Member
 
AppStoreMod's Avatar
 
Join Date: Jul 2009
Location: Sacramento,CA
Posts: 90
Send a message via Skype™ to AppStoreMod
Default

Quote:
Originally Posted by davidlansalot View Post
How often is your check collision method being called? If you have a timer that checks it every second or so, the object colliding with the other object could still be intersecting, therefore, the method gets called multiple times
every 0.05 seconds it calls the method to move the nails, and everytime the nail method is called so is the collision check
AppStoreMod is offline   Reply With Quote
Old 09-12-2009, 03:28 PM   #4 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

Quote:
Originally Posted by AppStoreMod View Post
every 0.05 seconds it calls the method to move the nails, and everytime the nail method is called so is the collision check
Invalidate your nstimer when you detect the collision so it won't call anymore
__________________
I really do this.
Bertrand21 is online now   Reply With Quote
Reply

Bookmarks

Tags
cgrectintersectrect, game, image, touch, void

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 276
26 members and 250 guests
ADY, Bertrand21, Dani77, Dattee, fkmtc, HDshot, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, sacha1996, silverwiz, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0