【发布时间】:2014-08-04 06:56:31
【问题描述】:
我试图用四个不同的矩形将屏幕分成四个不同的部分,如下所示:
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.width;
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.height;
CGRect jumpleftRect = CGRectMake(0, screenHeight/2, screenWidth/2, screenHeight/2); //1
CGRect runleftRect = CGRectMake(0, 0, screenWidth/2, screenHeight/2); //2
CGRect jumprightRect = CGRectMake(screenWidth/2, screenHeight/2, screenWidth/2, screenHeight/2); //3
CGRect runrightRect = CGRectMake(screenWidth/2, 0, screenWidth/2, screenHeight/2); //4
然后我在 touchArray 中循环并检查触摸位置是否在其中,例如对于这个问题,第一个矩形:
NSArray *touchArray = [NSMutableArray arrayWithArray:touchArray];
for (UITouch *touchInArray in touchArray) {
CGPoint toucharrayPosition = [touchInArray locationInNode:self];
if (CGRectContainsPoint(jumpleftRect, toucharrayPosition)) { //1st rect }
但是,似乎 rect 的位置完全错误。即使我的手指清楚地位于屏幕的左上角,这也不会被调用。我的 anchorPoints 没有受到影响并且正常,所以我不确定为什么这不起作用。是否有某些特定原因导致触摸没有像矩形一样注册,即使回想起来它们应该是?
【问题讨论】:
标签: ios cocos2d-iphone touch cgrect