触摸式旋转精灵libgdx

触摸式旋转精灵libgdx,libgdx,Libgdx,当我向左推动时,我正试图旋转我的精灵。现在,我的角色正在空转并向右运行。但是我无法向左旋转 这是我的代码块。如果有人能帮助我,那就太棒了 public void draw(SpriteBatch spriteBatch) { stateTime += Gdx.graphics.getDeltaTime(); //continue to keep looping if(Gdx.input.isTouched()){ int xTouch = Gdx.

当我向左推动时,我正试图旋转我的精灵。现在,我的角色正在空转并向右运行。但是我无法向左旋转

这是我的代码块。如果有人能帮助我,那就太棒了

public void draw(SpriteBatch spriteBatch) {
    stateTime += Gdx.graphics.getDeltaTime();
    //continue to keep looping




    if(Gdx.input.isTouched()){
        int xTouch = Gdx.input.getX();
        int yTouch = Gdx.input.getY();
        //System.out.println(Gdx.graphics.getWidth()/4);
        //go left
        if(xTouch < (width/4) && yTouch > height - (height/6)){
            currentRunFrame = runAnimation.getKeyFrame(stateTime, true);
            spriteBatch.draw(currentRunFrame,  runSprite.getX() - 32, runSprite.getY() + 150, 128, 128);
            RealGame.leftButton = new Texture(Gdx.files.internal("leftButtonOver.png"));
            moveLeft();
        }
        if(xTouch > (width/4) && xTouch < (width/4)*2 && yTouch > height - (height/6)){
            currentRunFrame = runAnimation.getKeyFrame(stateTime, true);
            spriteBatch.draw(currentRunFrame,  runSprite.getX() - 32, runSprite.getY() + 150, 128, 128);
            RealGame.rightButton = new Texture(Gdx.files.internal("rightButtonOver.png"));
            moveRight();
        }
        if(xTouch > (width/4) * 2 && xTouch < (width/4) * 3 && yTouch > height - (height/6)){
            RealGame.shootButton = new Texture(Gdx.files.internal("shootButtonOver.png"));
        }
        if(xTouch > (width/4) * 3 && xTouch < (width/4) * 4 && yTouch > height - (height/6)){
            RealGame.jumpButton = new Texture(Gdx.files.internal("jumpButtonOver.png"));
        }

    }
    if(!Gdx.input.isTouched()){

        currentIdleFrame = idleAnimation.getKeyFrame(stateTime, true);
        spriteBatch.draw(currentIdleFrame,  idleSprite.getX() - 32, idleSprite.getY() + 150, 128, 128);
        RealGame.leftButton = new Texture(Gdx.files.internal("leftButton.png"));
        RealGame.rightButton = new Texture(Gdx.files.internal("rightButton.png"));
        RealGame.shootButton = new Texture(Gdx.files.internal("shootButton.png"));
        RealGame.jumpButton = new Texture(Gdx.files.internal("jumpButton.png"));
        moveStop();

    }

}
public void draw(SpriteBatch-SpriteBatch){
stateTime+=Gdx.graphics.getDeltaTime();
//继续循环
if(Gdx.input.isTouched()){
int xTouch=Gdx.input.getX();
int-yTouch=Gdx.input.getY();
//System.out.println(Gdx.graphics.getWidth()/4);
//向左走
如果(X触摸<(宽度/4)和&Y触摸>高度-(高度/6)){
currentRunFrame=runAnimation.getKeyFrame(stateTime,true);
spriteBatch.draw(currentRunFrame,runSprite.getX()-32,runSprite.getY()+150128128);
RealGame.leftButton=新纹理(Gdx.files.internal(“leftButtonOver.png”);
左移();
}
如果(X触摸>(宽度/4)和&X触摸<(宽度/4)*2和&Y触摸>高度-(高度/6)){
currentRunFrame=runAnimation.getKeyFrame(stateTime,true);
spriteBatch.draw(currentRunFrame,runSprite.getX()-32,runSprite.getY()+150128128);
RealGame.rightButton=新纹理(Gdx.files.internal(“rightbutnover.png”);
moveRight();
}
如果(xTouch>(宽度/4)*2和&xTouch<(宽度/4)*3和&yTouch>高度-(高度/6)){
RealGame.shootButton=新纹理(Gdx.files.internal(“shootButtonOver.png”);
}
如果(xTouch>(宽度/4)*3和&xTouch<(宽度/4)*4和&yTouch>高度-(高度/6)){
RealGame.jumpButton=新纹理(Gdx.files.internal(“jumpButtonOver.png”);
}
}
如果(!Gdx.input.isTouched()){
CurrentIdleName=idleAnimation.getKeyFrame(stateTime,true);
spriteBatch.draw(currentIdleFrame,idleSprite.getX()-32,idleSprite.getY()+150128128);
RealGame.leftButton=新纹理(Gdx.files.internal(“leftButton.png”);
RealGame.rightButton=新纹理(Gdx.files.internal(“rightButton.png”);
RealGame.shootButton=新纹理(Gdx.files.internal(“shootButton.png”);
RealGame.jumpButton=新纹理(Gdx.files.internal(“jumpButton.png”);
移动停止();
}
}

提前感谢您,如果您需要更多信息,请告诉我。

使用采用布尔flipX参数的SpriteBatch绘制方法或调用Sprite上的flip


哦,如果这是你的主循环,停止像你一样加载纹理。在开始时加载它们,并根据需要交换它们。

我假设您的
currentIdleFrame
纹理
纹理区域
,而不是
精灵
。带有
纹理的
SpriteBatch
s绘制方法之一支持
flipX
flipY
。使用此选项,您可以翻转他,例如,如果您向左行走,但您的
纹理
朝向右侧。此外,它还支持旋转,旋转角度应为度

非常重要的注意事项:创建
新纹理
每个渲染循环。不要这样做。而是将所有的
纹理
加载到
纹理[]帧
中,并根据
状态时间
绘制正确的纹理。另外,请看一下
动画
课程,它将帮助您完成这一任务


希望我能帮上忙

谢谢你关于在循环中创建新按钮的提示。我试图弄明白为什么我的应用程序在26秒后就死掉了。好。。。现在我知道了为什么要在
create()
show()
constructor
中创建对象,因为它们只在实际需要时被调用一次。在渲染中创建
新对象
可能有点繁重,因此仅在绝对必要时使用它。