Skip to content
Snippets Groups Projects
Commit 32f71a42 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

Merge branch 'feature-pursuit_devel' into 'devel'

Fixed puzzle tiles cropping from textures atlas



See merge request !132
parents ec09c2f7 41523776
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ import cz.nic.tablexia.util.Log;
* Created by Václav Tarantík on 17.6.15.
*/
public class Grid extends Group {
private float size;
private int numberOfColumns;//number of rows respectively columns
private Map<Integer, PuzzlePiece> piecesMap;
private TextureRegion textureRegion;
......@@ -50,29 +50,29 @@ public class Grid extends Group {
//creates pieces texture regions and places them in the grid
private void placePieces() {
for (int i = 0; i < Math.pow(numberOfColumns, 2); i++) {
float pieceSize = getWidth() / (float) numberOfColumns;
cz.nic.tablexia.util.Point pieceRelativePosition = getPieceRelativePosition(i);
float relativePieceSize = pieceSize / getWidth();
float pieceSize = getWidth() / numberOfColumns;
//TextureRegion divided in parts for each piece
Log.info(getClass(), "Texture: " + textureRegion.getTexture() + " RPX: " + pieceRelativePosition.x + " RPSX: " + (pieceRelativePosition.x + relativePieceSize) + ", RPY: " + pieceRelativePosition.y + ", RPSY: " + (pieceRelativePosition.y + relativePieceSize) + ", SIZE: " + relativePieceSize * getWidth());
TextureRegion pieceRegion = new TextureRegion(textureRegion.getTexture(), pieceRelativePosition.x, pieceRelativePosition.y, pieceRelativePosition.x + relativePieceSize, pieceRelativePosition.y + relativePieceSize);
TextureRegion[][] split = textureRegion.split(textureRegion.getRegionWidth() / numberOfColumns, textureRegion.getRegionHeight() / numberOfColumns);
int i = 0;
for (TextureRegion[] splitX : split) {
for (TextureRegion splitXY : splitX) {
PuzzlePiece puzzlePiece = new PuzzlePiece(i, pieceRegion);
puzzlePiece.setSize(pieceSize, pieceSize);
puzzlePiece.setOrigin(pieceSize / 2, pieceSize / 2);
puzzlePiece.setZIndex(1);
PuzzlePiece puzzlePiece = new PuzzlePiece(i, splitXY);
puzzlePiece.setSize(pieceSize, pieceSize);
puzzlePiece.setOrigin(pieceSize / 2, pieceSize / 2);
puzzlePiece.setZIndex(1);
//in initial state, all pieces are at the correct positions
puzzlePiece.setCorrectPosition(i);
puzzlePiece.setActualPosition(i);
//in initial state, all pieces are at the correct positions
puzzlePiece.setCorrectPosition(i);
puzzlePiece.setActualPosition(i);
i++;
cz.nic.tablexia.util.Point pieceInitialPosition = getPieceGridPositionInPixels(i);
puzzlePiece.setPosition(pieceInitialPosition.x, pieceInitialPosition.y);
cz.nic.tablexia.util.Point pieceInitialPosition = getPieceGridPositionInPixels(i);
puzzlePiece.setPosition(pieceInitialPosition.x, pieceInitialPosition.y);
piecesMap.put(piecesMap.size(), puzzlePiece);
addActor(puzzlePiece);
piecesMap.put(piecesMap.size(), puzzlePiece);
addActor(puzzlePiece);
}
}
shufflePieces(random);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment