Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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, 05:24 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 104
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 05:27 AM.
ozzie is offline   Reply With Quote
Old 02-06-2010, 11:30 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,554
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);
__________________

Last edited by smasher; 02-06-2010 at 11:35 AM.
smasher is offline   Reply With Quote
Old 02-06-2010, 02:27 PM   #3 (permalink)
Lost in a sea of code
 
BostonMerlin's Avatar
 
Join Date: Apr 2008
Location: Boston
Posts: 388
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, 01:51 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,554
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.
__________________
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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,944
Threads: 38,725
Posts: 169,933
Top Poster: smasher (2,554)
Welcome to our newest member, mickeyargo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0