Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

problem with collision

$
0
0
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:
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?


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>