miércoles, 21 de diciembre de 2011

Comprobar que se ha pulsado dentro de un rectangulo libGDX

Sacado de el ejemplo SuperJumper que viene con libGDX
  import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class ComprobadorSuperposicion {
 public static boolean SuperposicionRectangulos (Rectangle r1, Rectangle r2) {
  if (r1.x < r2.x + r2.width && r1.x + r1.width > r2.x && r1.y < r2.y + r2.height && r1.y + r1.height > r2.y)
   return true;
  else
   return false;
 }

 public static boolean puntoEnRectangulo (Rectangle r, Vector2 p) {
  return r.x <= p.x && r.x + r.width >= p.x && r.y <= p.y && r.y + r.height >= p.y;
 }

 public static boolean puntoEnRectangulo (Rectangle r, float x, float y) {
  return r.x <= x && r.x + r.width >= x && r.y <= y && r.y + r.height >= y;
 }
}
 

No hay comentarios:

Publicar un comentario