我有一個簡單的問題 - 我試圖阻止拖動演員,但我看到奇怪的效果 - 當我試圖拖動演員開始閃爍並隨機更改位置。這裏是一個簡短的視頻:https://youtu.be/KpGujQ7KHc0奇怪的行爲與touchDragged
演員很簡單:
public class Item extends Actor {
private String id;
private TextureRegion texture;
public Item() {
this.id = "passport";
texture = PicturesData.getPicture(getId());
setSize(texture.getRegionWidth(), texture.getRegionHeight());
addListener(new DragListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
Log.add("Dragged: " + x + ", " + y);
setPosition(x, y);
}
});
}
public String getId() {
return id;
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(texture, getX(), getY());
}
}
屏幕是基本太:
public class GameScreen implements Screen {
private Stage stage;
public GameScreen() {
stage = new Stage(new StretchViewport(800, 600));
Gdx.input.setInputProcessor(stage);
Item item = new Item();
stage.addActor(item);
}
@Override
public void show() {
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
我不知道爲什麼它的發生,你能幫幫我嗎?
還有其它地方在你的代碼中這個演員的位置發生變化? –
不,我用屏幕代碼更新了我的帖子。這也是非常基本的。 – Pasha