 |
 |
|
 |
02-06-2010, 05:24 AM
|
#1 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 104
|
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.
|
|
|
02-06-2010, 11:30 AM
|
#2 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,554
|
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.
|
|
|
02-06-2010, 02:27 PM
|
#3 (permalink)
|
|
Lost in a sea of code
Join Date: Apr 2008
Location: Boston
Posts: 388
|
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:
|
|
|
02-07-2010, 01:51 AM
|
#4 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,554
|
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.
__________________
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 520 |
| 37 members and 483 guests |
| ArunSekhar, asiago, chris95, Duncan C, Dynno, EduardoFonseca, facebookapp110, frankie_121, funnystrike, gbaldwin9, HemiMG, hzc, jahpa3, Jompe71, Jume, korani, Kryckter, ledererc, Locker, MacBuddy, marktrasko, martaklein, nisarnadaf, not_too_shabby, pgrsv, prophox, reeceado, Robyn, scalar, scleland, sunny321hk, TheRunningMan, utah.johnny11, virvalid, wilky94, WRXFlyer |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 23,944
Threads: 38,725
Posts: 169,933
Top Poster: smasher (2,554)
|
| Welcome to our newest member, mickeyargo |
|