iijb Posted April 8, 2016 Share Posted April 8, 2016 Hi All, Im trying to create a puzzle game using the example game sliding puzzle . But in the game the pieces does not match the original image if all pieces combined. Is the algorithm of cutting the image to pieces is correct. Some pieces are missing. Please anyone have an idea? The code for pieces is , function prepareBoard() { var piecesIndex = 0, i, j, piece; BOARD_COLS = Math.floor(game.world.width / PIECE_WIDTH); BOARD_ROWS = Math.floor(game.world.height / PIECE_HEIGHT); piecesAmount = BOARD_COLS * BOARD_ROWS; shuffledIndexArray = createShuffledIndexArray(); piecesGroup = game.add.group(); for (i = 0; i < BOARD_ROWS; i++) { for (j = 0; j < BOARD_COLS; j++) { if (shuffledIndexArray[piecesIndex]) { piece = piecesGroup.create(j * PIECE_WIDTH, i * PIECE_HEIGHT, "background", shuffledIndexArray[piecesIndex]); } else { //initial position of black piece piece = piecesGroup.create(j * PIECE_WIDTH, i * PIECE_HEIGHT); piece.black = true; } piece.name = 'piece' + i.toString() + 'x' + j.toString(); piece.currentIndex = piecesIndex; piece.destIndex = shuffledIndexArray[piecesIndex]; piece.inputEnabled = true; piece.events.onInputDown.add(selectPiece, this); piece.posX = j; piece.posY = i; piecesIndex++; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.