Android 如何在使用isTouched()方法LibGDX时将精灵移动到手指位置
Im目前正在使用桌面启动器和此代码进行移动Android 如何在使用isTouched()方法LibGDX时将精灵移动到手指位置,android,libgdx,touch,Android,Libgdx,Touch,Im目前正在使用桌面启动器和此代码进行移动 if(Gdx.input.isKeyPressed(Keys.A)){ position.x -= speed; movement = "left"; } else if(Gdx.input.isKeyPressed(Keys.D)){ position.x += speed; movement = "righ
if(Gdx.input.isKeyPressed(Keys.A)){
position.x -= speed;
movement = "left";
}
else if(Gdx.input.isKeyPressed(Keys.D)){
position.x += speed;
movement = "right";
}
我想做的是当我的手指在精灵的左边时向左移动,当它在右边时向右移动
有什么想法吗
到目前为止,我还没有使用isTouched方法,只对Actors使用(TextButton)
非常感谢我建议您退房 这是一个非常基本和简单的游戏教程,用户将桶移动到手指所在的位置,当您单击精灵的右侧时移动桶,只需添加一个条件,如果您单击的位置大于精灵中心(spritewidth/2),则向右移动,如果小于,则向左移动
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(button == Buttons.LEFT){
posX = screenX - sprite.getWidth()/2;
posY = Gdx.graphics.getHeight() - screenY - sprite.getHeight()/2;
}
if(button == Buttons.RIGHT){
posX = Gdx.graphics.getWidth()/2 - sprite.getWidth()/2;
posY = Gdx.graphics.getHeight()/2 - sprite.getHeight()/2;
}
return false;
}
查看本教程,它提供了大量信息和说明:
和平