gpt4 book ai didi

java - libGDX 如果用户在触摸后移动手指,如何停止 touchUp 注册

转载 作者:行者123 更新时间:2023-11-30 07:08:38 25 4
gpt4 key购买 nike

我有一个 scrollPane,里面有几个 Actor 。每个 Actor 都注册了一个触摸事件以设置新屏幕,但用户显然希望能够在不注册触摸的情况下滚动 Actor 列表。我该怎么做? Actor 正在注册触摸事件,如下所示......

public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
octave3Btn.getColor().a = 0.25f;
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
octave3Btn.getColor().a = 1f;
launcher.setScreen(new ListNotesScreen(NoteNameAssets.octave3NoteNameArray,ImageAssets.octave3BtnTextureArray,manager, launcher));
}

最佳答案

使用 touchDragged 回调以了解两者之间是否存在阻力。

private boolean wasDragged = false;

public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
octave3Btn.getColor().a = 0.25f;
wasDragged = false;
return true;
}

public boolean touchDragged(InputEvent event, float x, float y, int pointer) {
// you can use a simple flag here, or better calculate the distance
// and set the flag when the distance surpassed a certain limit
wasDragged = true;
}

public boolean touchUp(InputEvent event, float x, float y, int pointer, int button) {
octave3Btn.getColor().a = 1f;
if (!wasDragged) {
launcher.setScreen(new ListNotesScreen(...));
}
}

这可能应该考虑到小错误。如果有 1px 的拖动事件,您可能不会设置标志。更好地计算触摸被拖动到 touchDown 之间的距离。和 touchUp然后切换屏幕以防distance < 10例如。

关于java - libGDX 如果用户在触摸后移动手指,如何停止 touchUp 注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23886695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com