I have three classes: Movement, Collision and Variables(The Variables class is where I store my variables and all of them are public and static. Considering I am new to java I don't really understand what the static keyword does, so my problem might be with the static keyword.). In my Collision class there is a method which checks for collision within the map. Now this method works perfectly:
public void checkCollision(int x, int y)
{
if (x == 100){
Variables.collisionRight = true;
} else {
Variables.collisionRight = false;
}
}
Here I have a method in my Movement class which does not work:
public void playerMovement (int x, int y)
{
if (RightKeyPressed == true & collisionRight == false) {
x += Variables.speed;
}
}
Here is how i call these methods:
someObject.checkCollision(Variables.playerX, Variables.playerY);
someOtherObject.playerMovement(Variables.playerX, Variables.playerY);
Seems to me the problem is that this line:
x += Variables.speed;
If i change
x
to
Variables.playerX
Everything works fine, but that's not how I want it to work.
It's not working. Which basically should be (Variables.playerX += Variables.speed) All the methods are samples.
I want to know why is my x (Variables.playerX) variable not incrementing by 3(which is my Variables.speed variable);