• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to check for collision

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

https://coderanch.com/t/582359/GUI/java/overlapping-jpanels
and
https://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: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, i am doing.
thank you michael..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic