how to drag and drop actors on libgdx scene2d?(如何在 libgdx scene2d 上拖放演员?)
问题描述
我正在使用 libGDX 开发游戏,我想知道如何拖放 Actor.我已经搭建好舞台并画好了演员,但我不知道如何触发该事件.
I'm developing a game using libGDX and I would like to know how I can drag and drop an Actor. I've made my stage and drawn the actor, but I don't know how to trigger that event.
请尝试帮助我使用我自己的架构.
Please try to help me using my own architecture.
public class MyGame implements ApplicationListener
{
Stage stage;
Texture texture;
Image actor;
@Override
public void create()
{
texture = new Texture(Gdx.files.internal("actor.png"));
Gdx.input.setInputProcessor(stage);
stage = new Stage(512f,512f,true);
actor = new Image(texture);
stage.addActor(actor);
}
@Override
public void render()
{
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.draw();
}
}
推荐答案
看看 libgdx 示例中的示例.这是来自 libgdx 测试类的拖放测试:DragAndDropTest
Take a look at the Example in the libgdx examples. Here is the drag and drop test from the libgdx test classes: DragAndDropTest
如果您只想拖动/滑动您的 Actor,您需要向其添加一个 GestureListener 并将您的 Stage 传递给 Inputprocessor,如下所示:Gdx.input.setInputProcessor(stage);
.这是 来自 libgdx 的 GestureDetectorTest.对于拖动事件,它是 Flinglistener.
If you just want to drag/slide your Actor around you need to add a GestureListener to it and pass your Stage to the Inputprocessor like this:Gdx.input.setInputProcessor(stage);
.
Here is the GestureDetectorTest from libgdx.
For drag events its the Flinglistener.
这篇关于如何在 libgdx scene2d 上拖放演员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 libgdx scene2d 上拖放演员?


基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java Swing计时器未清除 2022-01-01