【发布时间】:2010-10-20 21:19:14
【问题描述】:
我有一个简单的 OpenGL:ES 应用程序正在运行(它是一个游戏)。游戏加载并向用户显示“新游戏按钮”,然后您就进入了游戏。我正在使用 touchesBegan / touchesEnded 来处理触摸。然后我获取坐标并相应地处理它们。
我还有一个运行频率为 30Hz 的 NSTimer,它调用 renderScene 来绘制屏幕上的图形。
在设备上每隔一段时间(我还没有在模拟器上发生这种情况)我在第一个之后不再收到触摸事件。我试图在设备上调试它,似乎在我收到第一个 touchesEnded 事件后,设备被 touchesEnded 调用轰炸了。发生这种情况时,我再也没有接到过 touchesBegan 电话。如果我按下 home 键并回到游戏中,通常一切都会正常工作。
这是我的输入代码,因为它存在于我的 EAGLView.m 代码中
#pragma mark
#pragma mark UserInputStuff
#pragma mark
#pragma mark
#pragma mark touchesBegan
#pragma mark
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
firstTouch = [touch locationInView:self];
lastTouch = [touch locationInView:self];
[(MyGameAppDelegate*)[[UIApplication sharedApplication] delegate] HandleTouchEvent:firstTouch];
}
#pragma mark
#pragma mark touchesEnded
#pragma mark
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
lastTouch = [touch locationInView:self];
[(MyGameAppDelegate*)[[UIApplication sharedApplication] delegate] HandleTouchEnded:lastTouch];
}
这是我的应用程序委托中存在的代码
#pragma mark
#pragma mark HandleTouchEnded
#pragma mark A function to react to the touch that is no longer present on the screen
#pragma mark
- (void)HandleTouchEnded:(CGPoint)coordinate
{
if(_state == kState_Title)
{
[self TitleCollisionDetection:coordinate];
if(_buttonHighlighted)
{
_textures[kTexture_Background] = [[Texture2D alloc] initWithImage:[UIImage imageNamed:@"T4Background.png"]];
glBindTexture(GL_TEXTURE_2D, [_textures[kTexture_Background] name]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
[self resetGame];
}
}
}
这是配置用于处理渲染器的计时器的代码。
//Start rendering timer
_timer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / kRenderingFPS) target:self selector:@selector(renderScene) userInfo:nil repeats:YES];
[UIApplication sharedApplication].idleTimerDisabled = YES;
我显然在做一些愚蠢的事情。我错过了什么?为什么 touchesEnded 如此频繁地触发?
【问题讨论】:
标签: ios iphone cocoa-touch