私は単純なOpenGL:ESアプリケーションを実行しています(これはゲームです)。ゲームはロードされ、ユーザーに「新しいゲームボタン」が表示され、ゲームに参加しています。私はタッチを扱うためにtouchesBegan/touchesEndedを使用しています。それから私は座標を取ってそれに応じて処理します。touchesEnded
また、オンスクリーングラフィックスを描画するrenderSceneを呼び出す30Hzで動作するNSTimerがあります。
いつもデバイス上で(これはまだシミュレータ上で起こっている)私はもう最初のイベントの後にタッチイベントを取得しません。私はデバイス上でこれをデバッグしようとしています、そして、最初のtouchesEndedイベントが来たら、デバイスはtouchesEndedコールによって砲撃されます。私は決して別の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];
}
そして、ここに存在する。ここ
は、私の入力のためのコードである、それは私のアプリデリゲートに
#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は頻繁に発射ですか?
私はあなたが何かここで逃したと思います。 firstTouchコールは です。[(MyGameAppDelegate *)[[UIApplication sharedApplication] delegate] HandleTouchEvent:firstTouch]; 2番目は です。[(MyGameAppDelegate *)[[UIApplication sharedApplication] delegate] HandleTouchEnded:lastTouch]; – K2Digital