Just as in Game maker Studio there is an option for exact collisions so that objects collide only when a part of the colored image of an object collides with another part of the colored image, in java I use:
if(new Rectangle(x,y,ancho,alto).intersects(new Rectangulo(objeto.x, objeto.y, objeto.ancho, objeto.alto)){
//Colisiono
}
but this only detects a rectangle formed around the objects and I want that instead of rectangles, the collision is detected until where the color of the image begins without taking into account empty spaces.
If it can.
There is a method in Java that does what you want (collision of polygons) it works with the Shape class
shape.getBounds2D().intersects(other.getBounds2D())
, but it is somewhat complex to handle that class because you would have to specify the points that you want to make up the shape.On the other hand to evaluate the collisions you have other options:
Remember that the more precise the evaluation of the collision, the more computational resources will be used (there are even many more algorithms that you can consult), so if you want to keep it simple, continue with the rectangles.
Sources: GenbetaDev