So I have been trying to fix this for nearly an hour now, but I am truly clueless.... In my class MainGame i define 2 floats:

1 2

privatefloatlevelX = -500;privatefloatlevelY = -500;

and I also define a getter for both of those. When you press the up arrow key the levelY is decreased (using libgdx so it may be irregular seeing something like this) And I do the same for the rest of my arrow keys. Now the problem is when I am trying to use the value of the levelX or levelY in another class it always returns as -500 even though if I print out the value in the MainGame class it is changed from that original -500 but not in the other class.... Is this some stupid error I am not picking up on here or is it something deeper ?

Err you seem to not understand OOP. I advise you to learn more about Java before making games.

In your code, you are never calling mainGame.update() inside Resource however you claimed to be calling it, which leads me to believe you are using a different instance in a separate class. This means you don't understand how different instances are separate from each other.

@sparky83 you are definately right about that but how do I actually avoid creating a new instance of that? Do i have to use static getters / setters or something. I feel very foolish for not realizing this

I suggest you first do some Java tutorials as your questions are not related to game development but to Java and OO programming in general. A good place to start are the Java tutorials by Oracle:http://docs.oracle.com/javase/tutorial/

Shouldn't use static just because "normal" variables aren't working for you. levelX and levelY sound like iffy variables to make static, unless you only are ever going to have one level total (also, shouldn't you have a level class? and a player class?)Referring to the original question, are you somehow calling onCreate() excessively? By the method name I wouldn't think so but I'm only familiar with desktop libgdx. When is the getter called in relation to the setter?

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org