I am making a progress bar for showing the players current experience. However I have come around to a bug, which appears when the player is maxing out his experience and then is getting a new level. In the ideal world my code should reset the progress bar image width (which is a Scene2D image btw), but for some reason it is not setting the image width to zero, but is setting it to its full width instead, which I can't seem to understand why. I hope anyone can help me.
I have provided my code below, and also uploaded a video on youtube with my bug - Video of the bug
The method below is the one I use to change the experience progress bar width as well as the experience.
public void changeLevelExperience(int gainedExperience) {
float maxExpDividedInPixels = 131f / this.GAME.gameScreen.getGameManager().maxExperience;
this.GAME.gameScreen.getGameManager().currentExperience += gainedExperience;
if (this.GAME.gameScreen.getGameManager().currentExperience >= this.GAME.gameScreen.getGameManager().maxExperience) {
this.GAME.gameScreen.getGameManager().currentLevel++;
this.currentLevelLabel.setText(this.GAME.gameScreen.getGameManager().currentLevel + "");
//TODO: Another arrangement for the experience needs to be made.
this.GAME.gameScreen.getGameManager().maxExperience += 35;
this.GAME.gameScreen.getGameManager().currentExperience = 0;
Gdx.app.debug(TAG, this.GAME.gameScreen.getGameManager().currentExperience + "");
}
this.levelProgressBar.setWidth((int) (maxExpDividedInPixels * this.GAME.gameScreen.getGameManager().currentExperience * this.scaleFactor));
}