File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to check for collision

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
i have few images, moving inside a frame, i want to check collision between those images.
i tried it, i just prints the x and y coordinates of my images, but than what do i do i don't know.
do i need to do something like:-
create rectangles outside the images and check collision in between those rectangles, or something else??
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
these two threads deal with overlapping panels when dragged, but the principle
is basically the same if moving images in a JLabel

http://www.coderanch.com/t/582359/GUI/java/overlapping-jpanels
and
http://www.coderanch.com/t/573169/GUI/java/questions-JPanel

the second link is a bit long, but scattered throughout is some worthwhile reading relevant to your question
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you michael for replying.
thanks for the links, but i am not getting solution of my problem.
can you please please tell me what basic steps i need to follow, to check the collision.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> can you please please tell me what basic steps i need to follow, to check the collision.

the code in those links is almost identical to your problem - it's all to do with setLocation(),
and checking whether the new location collides/overlaps.

in the first link, my second last post is an example of dragging/checking overlap.
modify the code from:
1) dragging to animation setting-the-location
2) taking into consideration each label's size, instead of the 25x25 of the panels

and that would be one of the ways to solve your problem of rectangles (labels with images).
if you want the actual fish shapes colliding, then that's a whole lot more complex.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, i am doing.
thank you michael..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic