【发布时间】:2014-12-10 14:50:32
【问题描述】:
所以,我正在为 android 游戏创建一个游戏,所以在我的 Touching 类(实现 InputProcessor)中它看起来像:
public class Touching implements InputProcessor{
int y = 0;
int x = 0;
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
x = Gdx.input.getX();
y = Gdx.input.getY();
if (x > 122 && x < 202 && y > 620 && y < 700 )
{
Core.player1.anmov(2); //button 1
}
if ( x > 122 && x < 202 && y > 520 && y < 600)
{
Core.player1.anmov(1); //button 2
}
if (x > 20 && x < 100 && y > 620 && y < 700)
{
Core.player1.anmov(3); //button 3
}
if (x > 222 && x < 302 && y > 620 && y < 700)
{
Core.player1.anmov(4); // button 4
}
return true;
}
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
x = Gdx.input.getX();
y = Gdx.input.getY();
if (x > 122 && x < 202 && y > 620 && y < 700)
{
Core.player1.anmov(7); // button 1
}
if ( x > 122 && x < 202 && y > 520 && y < 600)
{
Core.player1.anmov(8); // button 2
}
if (x > 20 && x < 100 && y > 620 && y < 700)
{
Core.player1.anmov(5); // button 3
}
if (x > 222 && x < 302 && y > 620 && y < 700)
{
Core.player1.anmov(6); // button 4
}
return false;
}
public boolean touchDragged(int screenX, int screenY, int pointer) {
x = Gdx.input.getX();
y = Gdx.input.getY();
return true;
}
所以现在,如果我触摸代表在 X 上移动的按钮,拖动到代表在 Y 上移动的按钮,它仍然在 X 上移动,直到我的手指离开屏幕(touchUP 正在调用),然后,它站着,它在 Y 上不动..
有人可以帮帮我吗?我认为这是一个非常原始的方法,但我找不到解决方案。
【问题讨论】:
-
这是做你想做的事的坏方法......
-
@BoldijarPaul 这是评论问题的糟糕方式。尽量有建设性。
-
@BoldijarPaul 是对的,你不需要一个单独的类来处理你想要的简单事情。我只会在播放器类中编写运动。更糟糕的是你处理运动本身的方式与全球玩家领域。
-
@MennoGouw 我没有给他降价之类的,这就是问题所在,他正试图以错误的方式做某事。有大约 1000 种方法可以做到这一点..是的,也许我应该告诉他一个想法..但我不知道他的编程知识有多好..
-
@BoldijarPaul 只是说“这很糟糕”是没有用的,没有帮助任何人,只是乱扔问题。我会说这个用户介于绝对初学者和初学者之间。
标签: android libgdx touch draggable