- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行一个简单的 OpenGL:ES 应用程序(它是一个游戏)。游戏加载并向用户显示“新游戏按钮”,然后您就进入游戏了。我使用 TouchBegan/TouchEnded 来处理触摸。然后我获取坐标并相应地处理它们。
我还有一个以 30Hz 运行的 NSTimer,它调用 renderScene 来绘制屏幕图形。
每隔一段时间在设备上(我还没有在模拟器上发生这种情况)我在第一个触摸事件之后就不再收到触摸事件了。我尝试在设备上对此进行调试,似乎在我收到第一个 TouchEnded 事件后,设备就会受到 TouchEnded 调用的轰炸。发生这种情况时,我再也没有接到touchesBegan 电话。如果我按下主键并返回游戏,通常一切都会正常。
这是我的输入代码,它存在于我的 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];
}
这是我的应用程序委托(delegate)中存在的代码
#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;
我显然在做一些愚蠢的事情。我缺少什么?为什么 TouchEnded 如此频繁地触发?
最佳答案
实际上,第二次调用 NSTimer 时出现了错误
_timer = [NSTimer ScheduledTimerWithTimeInterval:(1.0/kRenderingFPS) target:self 选择器:@selector(renderScene) userInfo:nil 重复:YES];
这导致程序缺乏主线执行时间,因为它不断地为计时器例程提供服务。
性能分析器是您的 friend !!!我发现这一点是因为虽然我认为我的应用程序应该以 30 fps 运行,但我看到的结果超过 50 fps。起初我以为性能分析器坏了。事实证明,这是我的代码。
关于ios - 设备受到 TouchEnded 调用的轰炸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/773558/
我有一个发送到我的电子邮件的联系表,我最近受到了某种垃圾邮件攻击……我一夜之间从同一个 IP 地址收到了大约 76k 封电子邮件。这让我真的很生气。我该怎么做才能解决这个问题?我知道我可以实现验证码,
char *args = "echo hello world"; while(1) { pid_t pid = fork() if(pid == 0) { execlp
我是一名优秀的程序员,十分优秀!