I want to test my collision. I created a invisible rectangle, it would be my floor. And I have a character, it also has a rectangle around it. I'm using intersects() method here, but it seems that it doesn't work. Here is the main code parts:
In my character class I created a rectangle around it.
Here is method that returns that invisible rectangle.
Now my floor:
Everything looks fine. Now in my game class I'm trying to look for collision:
But it doesn't print anything. I add you screenshot, to see, that my character is on my rectangle. but it seems that they still don't collide. Where is problem?
rect = new Rectangle(x,y,65,90);
In my character class I created a rectangle around it.
public Rectangle getRect() { return rect; }
Here is method that returns that invisible rectangle.
Now my floor:
public class FloorCollision { private Rectangle rect; public FloorCollision() { rect = new Rectangle(0,400,600,205); } public Rectangle getRect() { return rect; } }
Everything looks fine. Now in my game class I'm trying to look for collision:
if(hero.getRect().intersects(fc.getRect())) System.out.println("Colissio");
But it doesn't print anything. I add you screenshot, to see, that my character is on my rectangle. but it seems that they still don't collide. Where is problem?