与UIImageView碰撞的精灵
UIImageView* debrisView = [[UIImageView alloc] initWithImage:object];
if(CGRectIntersectsRect(debrisView.frame, player.frame)){
NSLog(@"hit");
}
我的精灵只是通过我的UIImageView鬼魂。这是我正在使用的代码,希望能够检测到这两件事情正在发生。我把所有的物体随机产生在顶部并滴落下来。我的代码有什么问题?与UIImageView碰撞的精灵
在我 - (无效)viewDidLoad方法中,我有
debris = [UIImage imageNamed:@"object.png"];
NSLog
debrisView.frame
和player.frame
,看看他们都有自己设定框架。你也会更清楚地知道你的代码有什么问题。
[编辑]好,使事情变得更加容易:当您在使用代码
[self printFrame:debrisView.frame];
[self printFrame:player.frame];
我添加了NSLog(“@%f%f”,debrisView.frame,player.frame); 我看到我刚刚得到了非常大的数字,我没有看到你想说的。请解释?我很新的目标c。 – 2011-04-22 14:33:35
@Dustin检查编辑。 – 2011-04-22 14:44:40
'NSLog(@“%@”,NSStringFromCGRect(debrisView.frame));' – 2011-04-22 17:39:41
:
这样使用它?你必须检查每帧的碰撞... – Aymarick 2011-04-22 14:48:26