如何拖放演员在libgdx scene2d? [英] how to drag and drop actors on libgdx scene2d?
问题描述
我正在开发一个游戏使用libGDX,我想知道我可以拖放一个演员。我做了我的舞台和绘制的演员,但我不知道如何来触发该事件。
请尝试使用自己的架构来帮助我。
公共类MyGame实现了ApplicationListener
{
舞台阶段;
纹理质感;
图片演员;
@覆盖
公共无效创建()
{
纹理=新的纹理(Gdx.files.internal(actor.png));
Gdx.input.setInputProcessor(阶段);
舞台=新阶段(512F,512F,真正的);
演员=新的图像(纹理);
stage.addActor(演员);
}
@覆盖
公共无效渲染()
{
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.draw();
}
}
看看在libgdx例子为例。这里是拖动和从libgdx测试类跌落试验:<一href="https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/DragAndDropTest.java"相对=nofollow> DragAndDropTest
如果你只是想拖/在你身边需要一个GestureListener添加到它,你的舞台传递到Inputprocessor这样的滑动你的演员: Gdx.input.setInputProcessor(阶段);
。
这里是<一个href="https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/GestureDetectorTest.java"相对=nofollow> GestureDetectorTest 从libgdx。
对于拖动事件及其对Flinglistener。
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();
}
}
Take a look at the Example in the libgdx examples. Here is the drag and drop test from the libgdx test classes: DragAndDropTest
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!