在Android中创建一个按钮glSurfaceView
我在这方面有点问题。我想做一个按钮。但是,我不知道如何将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建自己的按钮类时,注册“触地”位置和“触地”位置。如果它们都已在按钮图形区域内注册,则按钮将被按下。
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.