gpt4 book ai didi

java - ActorGestureListener Fling 未注册

转载 作者:行者123 更新时间:2023-11-30 03:21:23 27 4
gpt4 key购买 nike

我无法让我的应用程序注册特定 Actor 的 throw Action 。当向 Actor 添加一个简单的tap并检查 table 上的点击时,我没有任何问题。对 flick 做同样的事情,但不起作用。我错过了什么吗?在网上到处找,并没有太多关于 ActorGestureListener 的信息。

我的代码:

    mainLeftTable.setTouchable(Touchable.enabled);
mainLeftTable.addListener(new ActorGestureListener(){
@Override
public void fling(InputEvent event, float velocityX, float velocityY, int button) {
System.out.println(velocityX + " - " + velocityY);
}
});

使用此代码没有任何反应,我看不到我错过了什么

仅供引用,设置 tap 可以使用以下代码:

    mainLeftTable.setTouchable(Touchable.enabled);
mainLeftTable.addListener(new ActorGestureListener(){
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
System.out.println("tapped");
}

我有我的舞台作为输入处理器。

更新:

显然是 ScrollPane 中的某些东西弄乱了它,如果我禁用 table 上的 ScrollPane,则 throw 会起作用。为什么是这样?我需要卷轴

最佳答案

您是否向 Gdx 应用程序提供有关监听器的信息?也就是说,调用:

Gdx.input.setInputProcessor(yourListener)

告诉应用程序您的新监听器?如果您有多个监听器,您可能需要使用 InputMultiplexer。不确定如何使用“tap”监听器设置其余代码。

我进行了快速搜索并浏览了以下教程,其中可能提供了一个可以重新用于代码的示例:

http://www.gamefromscratch.com/post/2013/10/24/LibGDX-Tutorial-5-Handling-Input-Touch-and-gestures.aspx

编辑:

根据评论,这里是一个可以运行的示例应用程序。我认为这就是您想要做的。

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;

public class Fling implements ApplicationListener {
private Texture music;
private SpriteBatch batch;
private OrthographicCamera camera;
private Stage stage;

@Override
public void create() {
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
batch = new SpriteBatch();

music = new Texture(Gdx.files.internal("img/sprites/buttons/music_off.png"));
Image image = new Image(music);
Table actor = new Table();
actor.debug();
actor.add(image).width(105).height(105);
actor.setX(100);
actor.setY(100);
actor.setTouchable(Touchable.enabled);
actor.addListener(new ActorGestureListener(){
@Override
public void fling(InputEvent event, float velocityX, float velocityY, int button) {
System.out.println(velocityX + " - " + velocityY);
}

@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
System.out.println("tapped");
}

@Override
public void touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchdown");
}

});
stage = new Stage();
stage.addActor(actor);

Gdx.input.setInputProcessor(stage);
}

@Override
public void render() {
stage.draw();
}

@Override
public void dispose() {
music.dispose();
batch.dispose();
}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}

}

当我运行它时,我看到: working fling

关于java - ActorGestureListener Fling 未注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244141/

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