1

テスト用の三目並べゲームを作成するために、次のルーチンがあります。しかし、問題は、ワンタッチであまりにも多くのイベントを取得していることです。isTouched() は down、up、move のすべてを返すのではないかと思います。イベントを起こす方法はありますか?

更新: 代わりに justTouched() を使用して問題を解決しました。

@Override
public void render() {
    // we update the game state so things move.
    updateGame();

    // First we clear the screen
    GL10 gl = Gdx.graphics.getGL10();
    gl.glViewport(0, 0, width, height);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    // Next we update the camera and set the camera matrix
    camera.update();
    camera.apply(Gdx.gl10);


    ...       
}
private void updateGame() {
    // the delta time so we can do frame independant time based movement
    float deltaTime = Gdx.graphics.getDeltaTime();


    // Has the user touched the screen? then position the paddle
    if (Gdx.input.isTouched() && !isProcess) {
        // get the touch coordinates and translate them
        // to the game coordinate system.
        isProcess=true;
        int width = Gdx.graphics.getWidth();
        int height = Gdx.graphics.getHeight();
        int offx=-width/2;
        int offy=-height/2;
        float x = Gdx.input.getX();
        float y = Gdx.input.getY();
        float touchX = 480 * (x
                / (float) width - 0.5f);
        float touchY = 320 * (0.5f - y
                / (float) height);
        for(int i=0;i<3;i++) {
            for(int j=0;j<3;j++)
            {
                if(touchX >= offx+i*width/3 && touchX < offx+(i+1)*width/3 &&
                        touchY >= offy+j*height/3 && touchY < offy+(j+1)*height/3)
                {
                    if(isCurrentO)
                        data[i][j]=CellStatus.O;
                    else
                        data[i][j]=CellStatus.X;
                    isCurrentO=!isCurrentO;
                    break;
                }
            }
        }
        isProcess=false;
    }

}
4

2 に答える 2

1

justTouched を使用する代わりに、 InputProcessorインターフェイスを実装することもできます。このインターフェイスには touchUp(x,y,pointer,button) があり、入力をより詳細に制御できます。これを実装するクラスがいくつかありますが、クラスに実装させることもできます。

于 2012-01-03T14:25:32.757 に答える
0

たとえば、(ハッシュ マップを使用して) ボードを作成し、ゲーム内の各オブジェクトをクリック可能にしたい場合、オブジェクトがタッチされてボード内にある場合、そのボードに追加され、イベントがキャッチされます。そうしないと、イベントをキャッチできません。とても簡単!:)

于 2013-03-14T15:06:52.497 に答える