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 02-06-2010, 06:24 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 140
Default Basic hit test.

Can anyone think why this isn't working? It's really simple but doesn't seem to work. The key is supposed to disappear when it touches the character which is animated by a simple UIView animation and it's called by:
Code:
[UIView setAnimationDidStopSelector:@selector(FinishedWalking)];
The problem is it seems to disappear almost randomly after you walk, even if you haven't collided with it. Heres the collision code:
Code:
-(void)FinishedWalking{
	if(CGRectIntersectsRect(Key.frame, Character.frame)){
		Key.hidden = YES;
		KeyObtained = YES;
	}
}
The key and Character and both inside the same UIView. Any help would be greatly appreciated.

Cheers,
Ozzie

Last edited by ozzie; 02-06-2010 at 06:27 AM.
ozzie is offline   Reply With Quote
Old 02-06-2010, 12:30 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

The code looks OK. Remember that it's checking rectangles, so if the rectangles overlap you'll have a collision, even if the visible parts of the images are not touching.

Also, the .frame property is not accurate when using a UIView animation. It only seems to tell you where the endpoint of the animation will be, not the "real" location of the image on the screen. You're only checking for collisions at the end of the animation though, so maybe your animations are short and that's OK?

If they had different parents you'd have to convert one of the rectangles; but you said "The key and Character and both inside the same UIView" -- do they both have the same direct parent? They're both children of the same view? Then that's OK too.

If it's still not working, put these logs inside your if statement and post the result for one of the "wrong" pickups.

Code:
NSLog(@"Character: %f,%f  %f,%f", Character.frame.origin.x, Character.frame.origin.y, Character.frame.size.width, Character.frame.size.height);
NSLog(@"Key: %f,%f  %f,%f", , Key.frame.origin.x, Key.frame.origin.y, Key.frame.size.width, Key.frame.size.height);
__________________

Free Games!

Last edited by smasher; 02-06-2010 at 12:35 PM.
smasher is offline   Reply With Quote
Old 02-06-2010, 03:27 PM   #3 (permalink)
Lost in a sea of code
 
BostonMerlin's Avatar
 
Join Date: Apr 2008
Location: Boston
Posts: 399
Default

be careful using @selector(animationDidStop:finished:context. My latest app was rejected for using that specific method.
__________________
----------------------------------------------------------------------
I love being a dad, flying airplanes and writing code.
----------------------------------------------------------------------
Follow me on Twitter: @BostonMerlin
Feed your brain on Twitter: @iPhoneDev101
----------------------------------------------------------------------
iPhone Apps:
BostonMerlin is offline   Reply With Quote
Old 02-07-2010, 02:51 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

That sounds like some kind of false positive; or were you calling the system method called animationDidStop:finished:context: ?

Using setAnimationDidStopSelector: is a perfectly valid and documented in the SDK. Maybe if you don't name your method animationDidStop:finished:context then you'll avoid the false positive.
__________________

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
» Stats
Members: 158,760
Threads: 89,201
Posts: 380,569
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jeeep
Powered by vBadvanced CMPS v3.1.0

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