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

Thread: Basic hit test.
View Single Post
Old 02-06-2010, 12:30 PM   #2 (permalink)
smasher
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
 

» Advertisements
» Online Users: 344
16 members and 328 guests
ADY, apatsufas, chemistry, Duncan C, Fit4him, headkaze, ilmman, MarkC, marto1914, Meoz, padsoftware, Promo Dispenser, Raffaello, tathaastu, tgjorgoski, Thrillhouse1919
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,222
Posts: 380,718
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:54 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.