Am I doing this collision check right?

this is right?

public BEntity collide(BEntity e1, String tipo,float x, float y,float wid, float hei)
    {
     //hitboxWidth = Image Width, hitboxHeight = Image height.
     Rectangle rectangle1 = new Rectangle(e1.x + x,e1.y + y,e1.hitboxWidth + wid,e1.hitboxHeight + hei);
     for(int i = 0; i < entities.size(); i++)
     {
      Rectangle rectangle2 = new Rectangle(entities.get(i).x,
              entities.get(i).y,entities.get(i).hitboxWidth,entities.get(i).hitboxHeight);
     if(e1 != entities.get(i)) 
     {
      if(rectangle1.intersects(rectangle2))
      {
       if(entities.get(i).type.equals(tipo) || tipo == null)
       {
        return entities.get(i);
       }
      }
     }
     }
     return null;
    }

and the getter:
collide(this,type,-1,+4,-1,-5);
to get the entity on left

For the most part, yes.
You need to be careful about creating new objects. If you are creating a new Rectangle in you update loop for every Entity, this will slow down the game. One way to solve this is to have that class (with the collide method) have to Rectangle object already created, and update the coordinates of the rectangle.
I’m not sure what you are doing with the line: (entities.get(i).type.equals(tipo) || tipo == null), but you may want to check that first.

Regards, :slight_smile:

Yeah thanks, but making a one-time rectangle has bugged my game. :stuck_out_tongue: its a bejewelled like game.

Edit: nothing, thanks the rectangles worked!

What exactly is bugged?

If the type is the type of object, for instance only specific entity types should collide with each other, then this:

if(rectangle1.intersects(rectangle2))
      {
       if(entities.get(i).type.equals(tipo) || tipo == null)
       {

Should be reversed. You should check to see if the types are the same before checking if their rectangles intersect.

No problem, I only had make something wrong, they are working good now.
And about the tipo, I’ve put them in the top of ifs. thanks both of you. and sorry for bad english