【发布时间】:2011-06-28 09:16:22
【问题描述】:
我有两个图像 image1 和 image2,当它们发生碰撞时我想“做点什么”,但我不知道碰撞的代码以及我们是否需要一个用于碰撞方法的计时器。请问我该怎么做?
【问题讨论】:
标签: iphone xcode methods uiimageview collision-detection
我有两个图像 image1 和 image2,当它们发生碰撞时我想“做点什么”,但我不知道碰撞的代码以及我们是否需要一个用于碰撞方法的计时器。请问我该怎么做?
【问题讨论】:
标签: iphone xcode methods uiimageview collision-detection
如果你安排一个计时器作为运行循环
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myRunloop) userInfo:nil repeats:YES];
然后在那个运行循环中检查冲突
- (void)myRunloop
{
// check collision
if( CGRectIntersectsRect(image1.frame, image2.frame) )
{
// ..do your stuff.. //
}
}
你已经完成了:-)
【讨论】: