Skip to content
Advertisement

Trying to update a boolean from a class in another class D:

First of all, sorry for my english!

I have a problem, I´m trying to make a simple java videogame, and I make booleans for the inputs. The inputs works well, but when I try to update the booleans in another class, it doesnt work.

I put here the important classes

I put all the classes in this drive. Classes

JavaScript
JavaScript

I only want the update function get the boolean variables, for me to be able to move my character. Thank you so much!

Advertisement

Answer

I had a look at the other classes and the reason is outside the code above, it’s in class Launcher.Main:

JavaScript

in here you create a new instance of class WindowPanel, which – by itself – create a another instance of GamePanel.

JavaScript

So, the GamePanel that you created in Main, after you created the WindowPanel is not related to the GamePanel you create afterwards and start threading.

Fix:

  • remove the additional GamePanel from Main class
  • add to the end of windowPanel() method in WindowPanel class:
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement