+ 2

Detecting Sprite Collision (Java)

I have a sprite class...now I want sprites I create with this class to detect collision with each other or among themselves.

4th Feb 2018, 12:33 AM
omensah
omensah - avatar
2 Réponses
+ 4
To check for collision, add a Rectangle variable in the sprite class and create a new Rectangle for each sprite with the position and size of the object. You can draw a rectangle with graphics using the Rectangle's values to have visual appearance of its position. Create some other class and call it 'Collision' and use the method I sent you.. p.s. Don't forget to move the Rectangles to the sprite's position every time they move.. https://code.sololearn.com/c9Vmu1vznWF4/?ref=app
4th Feb 2018, 2:47 AM
Robert Sokolov
Robert Sokolov - avatar
0
@Robby S, thanks a lot.
4th Feb 2018, 9:47 AM
omensah
omensah - avatar