首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字符绘制不正确,会在错误的位置出现一秒钟。

问字符绘制不正确,会在错误的位置出现一秒钟。
EN

Stack Overflow用户
提问于 2015-10-01 01:33:44
回答 1查看 58关注 0票数 0

所以,这是我的问题,我不确定这里的交易是什么,但它应该是相当简单的。我有一个纹理,我想要画在屏幕的左边或右边的屏幕。当屏幕的相应一侧被触摸时

调用该方法的方法:

代码语言:javascript
复制
public void screenTouched() {

    if (Gdx.input.justTouched()) {
        main_char.updateMainCharacter(Gdx.input.getX(), main_char.getPosition().y);
    }

移动纹理的方法:

代码语言:javascript
复制
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;
        }

    }

这是问题的图片

​

​

​

EN

回答 1

Stack Overflow用户

发布于 2015-10-01 02:32:46

问题在于你对运营商的选择&而不是&。

好的,这里是:

它的移动是因为每个循环只处理他的双条件的一部分。因此,如果他从每一项中删除&&,他将很快看到他的逻辑上的改进。

见此处:Difference between & and && in Java?

这将为你解释一切。

:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32878132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档