Tile Collision

I have multiple tiles in an array. I want to set collision between them and the player. Currently, I am trying to do the collision check by a static boolean in the player class, but with this:

if(tile[i].collision) {
Player.collision = true;
}else{
Player.collision = false;
}

I’m guessing you can tell that if any of the tiles do not have the collision, neither does the player. Does anybody know what I should do?

Thanks!

Static boolean?! Why?! :o

Make a non-static method called collideWith(Tile tile) in player which you just call when the player collides with a tile.

I thought i needed to use a boolean though, so I can only allow jumping if there is a tile below the player, and only allow falling if there isn’t.

That stuff is handled privately and non-statically inside the Player class.

-  if(tile[i].collision) {
-     Player.collision = true;
-  }else{
-     Player.collision = false;
-  }

+  Player.collision = tile[i].collision;

Ooh first real use of the correcting feature :slight_smile: