• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

awt.Shape intersect between different shapes

 
Tim Sangster
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to make a game for school.
In this game I simulate collision by using the .collision function of the awt.Shape 's I am using.
Now I am adding an object that is not a rectangle and I see that you can not use intersect for a comparison between different shapes.
Is there any build in way to still compare these?

Thanks in advance,

Tim
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What collision method? (Don't say "function").

Can't think of anything offhand. There are several intersects and contains methods in the GeneralPath class, but I don't know whether they are any improvement for you.

I shall move this discussion to our GUIs forum, where we usually discuss such questions.
 
Tim Sangster
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved
I used the Java 2D Shape Implementations
I want to check if a Rectangle2D intersects with a Ellipse2D.Double or Ellipse2D.Float.
The intersect method I used of java.awt.Shape can only be passed a Rectangle2D Object.
But the problem is solved by calling the intersect method on the Ellipse2D and passing the Rectangle2D instead of the other way around.

If anybody could explain to me why you can not simply compare all shapes (now at least one of them has to be a Rectangle2D) I would be very thankful.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done Don't know why you can only do it that way round. Maybe if I really remember to move you to GUIs somebody there will know. [Even though they are the same people you meet here ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic