2011-04-22 121 views
1
 UIImageView* debrisView = [[UIImageView alloc] initWithImage:object]; 
     if(CGRectIntersectsRect(debrisView.frame, player.frame)){ 
     NSLog(@"hit"); 
     } 

我的精靈只是通過我的UIImageView鬼魂。這是我正在使用的代碼,希望能夠檢測到這兩件事情正在發生。我把所有的物體隨機產生在頂部並滴落下來。我的代碼有什麼問題?與UIImageView碰撞的精靈

在我 - (無效)viewDidLoad方法中,我有

debris = [UIImage imageNamed:@"object.png"]; 
+0

-(void) printFrame:(CGRect frame) { NSLog(@"origin = (%f, %f)\n size = (%f, %f)", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height) } 

這樣使用它?你必須檢查每幀的碰撞... – Aymarick 2011-04-22 14:48:26

回答

1

NSLogdebrisView.frameplayer.frame,看看他們都有自己設定框架。你也會更清楚地知道你的代碼有什麼問題。

[編輯]好,使事情變得更加容易:當您在使用代碼

[self printFrame:debrisView.frame]; 
[self printFrame:player.frame]; 
+0

我添加了NSLog(「@%f%f」,debrisView.frame,player.frame); 我看到我剛剛得到了非常大的數字,我沒有看到你想說的。請解釋?我很新的目標c。 – 2011-04-22 14:33:35

+0

@Dustin檢查編輯。 – 2011-04-22 14:44:40

+0

'NSLog(@「%@」,NSStringFromCGRect(debrisView.frame));' – 2011-04-22 17:39:41