从touchesBegan获取触摸位置? (和其他游戏问题)

时间:2022-06-01 17:56:46

I'm trying to get the location of the touch event on the screen from

我正试图从屏幕上获取触摸事件的位置

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event.

- (void)touchesBegan:(NSSet *)触及withEvent:(UIEvent *)事件。

What code can I use to read the touch coordinates? I've gotten this far so far:

我可以用什么代码来读取触摸坐标?到目前为止,我已经走到了这一步:

NSLog(@"Touch data: %@", [NSString stringWithFormat:@"NSSet: %@",[touches description]]);

I'm trying to make a game using an OpenGL template application. The touches will only register in the EAGLView file, not the ESRenderer1 file. I assume that I should use the EAGlView to set variables and then read the variables from there into the ESRenderer to perform game calculations. Is this a good approach?

我正在尝试使用OpenGL模板应用程序制作游戏。触摸仅在EAGLView文件中注册,而不是在ESRenderer1文件中注册。我假设我应该使用EAGlView来设置变量,然后从那里读取变量到ESRenderer来执行游戏计算。这是一个好方法吗?

1 个解决方案

#1


16  

The following code does it:

以下代码执行此操作:

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'
}

#1


16  

The following code does it:

以下代码执行此操作:

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'
}