所以,这是我的问题,我不确定这里的交易是什么,但它应该是相当简单的。我有一个纹理,我想要画在屏幕的左边或右边的屏幕。当屏幕的相应一侧被触摸时
调用该方法的方法:
public void screenTouched() {
if (Gdx.input.justTouched()) {
main_char.updateMainCharacter(Gdx.input.getX(), main_char.getPosition().y);
}移动纹理的方法:
public void updateMainCharacter(float touch_pos_x, float pos_y) {
//main_char is already on left side
if (position.x < ClimberDude.V_WIDTH / 2 && touch_pos_x < ClimberDude.V_WIDTH / 2) {
position.x = 0;
position.y = pos_y + main_char.getHeight();
}
//main_char is already on right side
else if (position.x > ClimberDude.V_WIDTH / 2 && touch_pos_x > ClimberDude.V_WIDTH / 2) {
position.x = ClimberDude.V_WIDTH - main_char.getWidth();
position.y = pos_y + main_char.getHeight();
}
else if (touch_pos_x < ClimberDude.V_WIDTH / 2) {
position.x = 0;
position.y = pos_y;
}
else if (touch_pos_x > ClimberDude.V_WIDTH / 2) {
position.x = ClimberDude.V_WIDTH - main_char.getWidth();
position.y = pos_y;
}
}这是问题的图片


发布于 2015-10-01 02:32:46
问题在于你对运营商的选择&而不是&。
好的,这里是:
它的移动是因为每个循环只处理他的双条件的一部分。因此,如果他从每一项中删除&&,他将很快看到他的逻辑上的改进。
见此处:Difference between & and && in Java?
这将为你解释一切。
:)
https://stackoverflow.com/questions/32878132
复制相似问题