当我向左推时,我正在尝试旋转我的精灵。现在我的角色正在空转并向右跑。但我无法向左转。
这是我的一大堆代码。如果有人能帮助我,那就太棒了。
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();
}
}
提前感谢您,如果您需要更多信息,请告诉我。
答案 0 :(得分:1)
我认为您的currentIdleFrame
是Texture
或TextureRegion
,而不是Sprite
。使用SpriteBatch
的{{1}}绘制方法之一支持Texture
和flipX
。使用此功能,您可以翻转他,例如,如果您向左走,但flipY
朝向右侧。这也支持Texture
,它应该是度数的旋转。
Verry重要提示:您在每个渲染循环中创建rotation
。不要这样做。而是将所有new Texture
加载到Texture
中并绘制正确的Texture[] frames
,具体取决于stateTime
。另请查看Animations
课程,它将为您提供帮助。
希望我能提供帮助
答案 1 :(得分:0)
使用SpriteBatch绘制方法,该方法在Sprite上采用boolean flipX参数或调用flip。
哦,如果这是你的主循环,就像你一样停止加载纹理。在开头加载它们,然后根据需要交换它们。