我正在尝试从
获取屏幕上触摸事件的位置-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
。
我可以使用什么代码来读取触摸坐标?到目前为止我已经做到了:
NSLog(@"Touch data: %@", [NSString stringWithFormat:@"NSSet: %@",[touches description]]);
我正在尝试使用 OpenGL 模板应用程序制作游戏。触摸只会在 EAGLView
文件中注册,而不是在 ESRenderer1
文件中。我假设我应该使用 EAGlView 设置变量,然后将变量从那里读取到 ESRenderer 中以执行游戏计算。这是一个好方法吗?
最佳答案
下面的代码可以做到这一点:
NSArray *touchesArray = [touches allObjects];
for(int i=0; i<[touchesArray count]; i++)
{
UITouch *touch = (UITouch *)[touchesArray objectAtIndex:i];
CGPoint point = [touch locationInView:nil];
// do something with 'point'
}
关于iphone - 从touchesBegan获取触摸位置? (以及其他游戏问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176304/