I have a sprite that I want to rotate smoothly and face the opposite direction:
This is my render function:
public void render() {
// Game Loop
Gdx.gl.glClearColor(0.7f, 0.7f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
if(bug.getX() >= (int)(Gdx.graphics.getWidth() - 100) && bug.getY() >= (int)(Gdx.graphics.getHeight() - 100)){
bug.rotate(rotDeg);
turn = !turn;
}
else if(bug.getX() <= 0 && bug.getY() <= 0){
bug.rotate(rotDeg);
turn = !turn;
}
if(!turn){
bug.translate(v.x * Gdx.graphics.getDeltaTime(), v.y * Gdx.graphics.getDeltaTime());
}
else{
bug.translate(-(v.x * Gdx.graphics.getDeltaTime()), -(v.y * Gdx.graphics.getDeltaTime()));
}
bug.draw(spriteBatch);
spriteBatch.end();
}
What my code does is that when it reaches the destination (top right corner, or bottom left corner), it immediatly turns facing the opposite direction. How would I make this turn smoothly?