0

私は GLTextureLoader クラスを使用して画像をロードし、これらのスプライトが計算された速度で左から右に移動している openGL を使用してゲームを開発しようとしています。これらの画像のタッチを検出する必要があります。

4

3 に答える 3

1

あなたの目的は非常に単純なので、あなたがしなければならないことは、あなたが2回持っているオブジェクトを描画することだけです。次に、ユーザーが非表示のバッファで押した場所を確認し、それが何色であるかを確認すると、そこにオブジェクトがあります。

http://www.lighthouse3d.com/opengl/picking/index.php3?color1

それが基本理論です。

于 2012-07-26T07:27:40.583 に答える
0

OpenGL はレンダリング API です。それはものを描くだけです。lighthouse3d のような手法は機能しますが、glReadPixels は低速で​​す。

これは CPU で確認する必要があります。つまり、描画されたスプライトごとに、タッチ位置が内側にあるかどうかをテストします。

于 2012-07-26T08:04:13.417 に答える
0

私の要件に従って、それを行う方法を見つけました。私が言ったように、私はopenGLの専門家ではありませんが、何とかそれを行うことができました。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
CGPoint touchLocation = [touch locationInView:self.view];
touchLocation = touchLocation = CGPointMake(touchLocation.x, 320 - touchLocation.y);
//self.player.moveVelocity = GLKVector2Make(50, 50);
//NSLog(@"Location in view %@", NSStringFromCGPoint(touchLocation));
//NSLog(@"bounding box is %@",NSStringFromCGRect([self.player boundingBox]));

GameSprite *temp;
for (GameSprite *tempSprite in self.children) {
    if (CGRectContainsPoint([tempSprite boundingBox], touchLocation)) {
        NSLog(@"touched the player");

        temp =tempSprite;
    }  
}

[self.children removeObject:temp];

}

- (CGRect)boundingBox {
CGRect rect = CGRectMake(self.position.x, self.position.y, self.contentSize.width, self.contentSize.height);
return rect;
}
于 2012-07-26T11:12:27.373 に答える