I am making a collision detection method in my lwjgl game but it is not really working out. I am using Rectangles to check if they intersect. This is how I do it:
I have a Player that moves with the wasd buttons and I give him a Rectangle like this:
private Rectangle Collider;
public Player(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
Collider = new Rectangle(x, y, width, height);
}
public Rectangle getCollider() {
return Collider;
}
I have an Item that looks like this:
private Rectangle Collider;
public Item(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
Collider = new Rectangle(x, y, width, height);
}
public Rectangle getCollider() {
return Collider;
public void Update(){
System.out.println("Updating Item");
if(Canvas.iscolliding(game.player.getCollider(), this.getCollider)){
System.out.println("Colliding");
}
}
}
And this is my iscolliding method:
public static boolean isColliding(Rectangle a, Rectangle b) {
if (a.intersects(b)) {
return true;
} else {
return false;
}
}
But it never prints colliding why? (I use the LWJGL Rectangle not the java.awt).