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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 01-13-2010, 12:56 PM   #1 (permalink)
Registered Member
 
haza100's Avatar
 
Join Date: Jul 2009
Location: England
Posts: 81
haza100 is on a distinguished road
Default CGRectContinsRect problem

hi,
i have a problem with the function if CGRectContainsRect... i only want the score to +1 when a CGRect contains another, and i want the score to +1 only when the user has let go of the CGRect, at the moment if you drag the CGrect inside the other CGRect the score is constantly increasing, and you also don't have to let go of the CGRect, heres my code. Its very simple but i thought it would do the job, but at the moment it isn't.

- (void)touchesMovedNSSet *)touches withEventUIEvent *)event {
UITouch *myTouch = [[event allTouches] anyObject];
bomb.center = [myTouch locationInView:self];

[self checkCollision];
}

- (void)checkCollision {

if(CGRectContainsRect(redzone.frame, bomb.frame)) {

[self addScore];

}
}

- (void) addScore {
{
score = score +=1;
}

scoreLabel.text = [NSString stringWithFormat:@"%d", score];
}



Thanks, haza.
haza100 is offline   Reply With Quote
Old 01-13-2010, 01:43 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

If you want this to trigger when they drop the CGRect then you probably want to trigger it on "touchesEnded:withEvent:" , not on "touchesMoved:withEvent:"
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-13-2010, 02:18 PM   #3 (permalink)
Registered Member
 
haza100's Avatar
 
Join Date: Jul 2009
Location: England
Posts: 81
haza100 is on a distinguished road
Default

yeah, but the you cant actually see the CGRect move with your finger so it looks wierd.
is there any way to make it follow your finger and use the touchedEnded function at the same time.
thanks.
haza100 is offline   Reply With Quote
Old 01-13-2010, 03:44 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by haza100 View Post
yeah, but the you cant actually see the CGRect move with your finger so it looks wierd.
is there any way to make it follow your finger and use the touchedEnded function at the same time.
thanks.
Then keep the bomb.center=blah in touchesMoved, but move the [self checkCollision] into touchesEnded.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

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: 340
11 members and 329 guests
2Apps1Day, akacaj, Domele, michelle, NetGuru, NSString, SLIC, Sloshmonster, soohyun, Techgirl-52, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

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