M core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java +19 -2
@@ 14,6 14,7 @@
package net.dermetfan.jigsawPuzzle.puzzle;
+import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
@@ 39,8 40,8 @@ public class JigsawPuzzle {
private final SnapshotArray<Piece> placedPieces, remainingPieces;
public JigsawPuzzle() {
- remainingPieces = new SnapshotArray<Piece>();
- placedPieces = new SnapshotArray<Piece>();
+ remainingPieces = new SnapshotArray<Piece>(Piece.class);
+ placedPieces = new SnapshotArray<Piece>(Piece.class);
}
/** @param pieces the amount of pieces that will probably be in this puzzle */
@@ 118,12 119,14 @@ public class JigsawPuzzle {
/** @return the {@link #placedPieces} */
public Piece[] getPlacedPieces() {
placedPieces.end();
+ placedPieces.shrink();
return placedPieces.begin();
}
/** @return the {@link #remainingPieces} */
public Piece[] getRemainingPieces() {
remainingPieces.end();
+ remainingPieces.shrink();
return remainingPieces.begin();
}
@@ 242,6 245,20 @@ public class JigsawPuzzle {
slotX = slotY = 0;
}
+ private final Polygon tmpPolygon = new Polygon();
+
+ @Override
+ public Actor hit(float x, float y, boolean touchable) {
+ Actor hit = super.hit(x, y, touchable);
+ if(hit == this) {
+ tmpPolygon.setVertices(((PolygonRegionDrawable) getDrawable()).getRegion().getVertices());
+ tmpPolygon.setPosition(-slotX, -slotY);
+ if(!tmpPolygon.contains(x / getWidth() * GeometryUtils.width(tmpPolygon.getVertices()), y / getHeight() * GeometryUtils.height(tmpPolygon.getVertices())))
+ return null;
+ }
+ return hit;
+ }
+
/** @param ref the piece in relation to which to snap into this piece's spot */
public void snap(Piece ref) {
Vector2 refPuzzlePoint = Pools.obtain(Vector2.class).set(ref.getX(), ref.getY()).sub(ref.slotX, ref.slotY);
M core/src/net/dermetfan/jigsawPuzzle/screens/PlayScreen.java +2 -2
@@ 133,8 133,8 @@ public class PlayScreen extends ScreenAd
}
});
- dialog.getContentTable().add(board).expand().fill().minSize(bank.getWidth(), bank.getHeight()).row();
- dialog.getContentTable().add(bank).expand().fill();
+ dialog.getContentTable().add(board).expand().fill().row();
+ dialog.getContentTable().add(bank).expand().fill().minSize(bank.getWidth(), bank.getHeight());
dialog.show(stage);
}
M core/src/net/dermetfan/jigsawPuzzle/utils/Board.java +2 -2
@@ 15,11 15,11 @@
package net.dermetfan.jigsawPuzzle.utils;
import com.badlogic.gdx.scenes.scene2d.Actor;
-import com.badlogic.gdx.scenes.scene2d.Group;
+import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
/** a group that simply wraps its size around its children in {@link #pack()}
* @author dermetfan */
-public class Board extends Group {
+public class Board extends WidgetGroup {
/** wraps this Board's size around its children */
public void pack() {