@@ 14,7 14,7 @@
package net.dermetfan.jigsawPuzzle.puzzle;
-import com.badlogic.gdx.math.Polygon;
+import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
@@ 115,9 115,6 @@ public class JigsawPuzzle {
/** the position of the piece on the puzzle (the {@link PolygonRegionDrawable#getPolygonX() minX} and {@link PolygonRegionDrawable#getPolygonY() minY} of its vertices) */
private float slotX, slotY;
- /** temporary Polygon for internal use */
- private final Polygon tmpPolygon = new Polygon();
-
public Piece(Drawable drawable) {
super(drawable);
}
@@ 138,9 135,8 @@ public class JigsawPuzzle {
Actor hit = super.hit(x, y, touchable);
PolygonRegionDrawable drawable = getDrawable() instanceof PolygonRegionDrawable ? (PolygonRegionDrawable) getDrawable() : null;
if(hit == this && drawable != null) {
- tmpPolygon.setVertices(drawable.getRegion().getVertices());
- tmpPolygon.setPosition(-slotX, -slotY);
- if(!tmpPolygon.contains(x / getWidth() * drawable.getPolygonWidth(), y / getHeight() * drawable.getPolygonHeight()))
+ float[] vertices = drawable.getRegion().getVertices();
+ if(!Intersector.isPointInPolygon(vertices, 0, vertices.length, x / getWidth() * drawable.getPolygonWidth() + slotX, y / getHeight() * drawable.getPolygonHeight() + slotY))
return null;
}
return hit;