iphone - 从touchesBegan获取触摸位置? (以及其他游戏问题)

标签 iphone opengl-es touch

我正在尝试从

获取屏幕上触摸事件的位置

-(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/

相关文章:

ios - 如何禁用或隐藏数字键盘类型的本地化?

iphone - 将 3d 对象中心坐标转换为 2d 可见视口(viewport)坐标

java - Android 在可触摸区域绘制

javascript - 如何使用 hammer.js jQuery 插件设置不同的速度来识别滑动?

ios - 标签栏更改后重新加载页面

iphone - 如何在更改 UIImageView 时制作动画

php - 这可能是移动设备的有效用户代理吗?

android - 在OpenGL中与法线共享顶点索引

ios - 非常慢的软件矢量,尤其是 CoreGraphics 与 OpenGL

c# - Unity 滑动功能问题