开发者

Create a Button glSurfaceView in Android

开发者 https://www.devze.com 2023-03-22 19:51 出处:网络
I\'m having a bit of a problem with开发者_如何学JAVA this. I wanted to make a push button. However, I don\'t know how to use the Button class with OpenGL. I am not using the \"R\" class within Java in

I'm having a bit of a problem with开发者_如何学JAVA this. I wanted to make a push button. However, I don't know how to use the Button class with OpenGL. I am not using the "R" class within Java instead I am using the old "assets" folder for compatibility.

I have it setup to find if you have touched the button and on "touch up" load the next screen. The flaw in this is that you can touch the screen and then drag your finger over to the button and then lift your finger. The next screen will load, because it has registered the touch up event at that position.

The easiest way to fix this would be to use the Button class, but how do I use it (especially because I won't be able to use findViewById)?

This is the code I was using but when onTouchUp check for a collision touchDown has magically changed to be the same as TouchUp?

private void onTouchDown(Vector2 point)
{
    if (test.justUp)
    {
        test.setTouchDown(point);
        test.justUp = false;
    }
}
private void onTouchUp(Vector2 point)
{
    test.setTouchUp(point);
    test.justUp = true;

    if(OverlapTester.pointInRectangle(test.bounds, test.touchUp) &&
       OverlapTester.pointInRectangle(test.bounds, test.touchDown))
    {
        game.setScreen(new LevelSelect(game));
        return;
    }
}


When creating your own button class, register the "touch down" position and the "touch up" position. If they've both been registered inside your button graphic area, the button is pressed.

0

精彩评论

暂无评论...
验证码 换一张
取 消