在Android中创建一个按钮glSurfaceView

发布于 2024-11-26 09:15:49 字数 892 浏览 1 评论 0原文

我在这方面有点问题。我想做一个按钮。但是,我不知道如何将 Button 类与 OpenGL 一起使用。我没有在 Java 中使用“R”类,而是使用旧的“assets”文件夹来实现兼容性。

我将其设置为查找您是否已触摸按钮并在“触摸”时加载下一个屏幕。这样做的缺陷是您可以触摸屏幕,然后将手指拖到按钮上,然后抬起手指。将加载下一个屏幕,因为它已在该位置注册了触摸事件。

解决此问题的最简单方法是使用 Button 类,但如何使用它(特别是因为我无法使用 findViewById)?

这是我正在使用的代码,但是当 onTouchUp 检查碰撞时,touchDown 已经神奇地更改为与 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;
    }
}

I'm having a bit of a problem with 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;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的呼吸 2024-12-03 09:15:49

创建自己的按钮类时,注册“触地”位置和“触地”位置。如果它们都已在按钮图形区域内注册,则按钮将被按下。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文