Skip to content

Commit

Permalink
changed offset to page in click event - fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeeejeets committed Apr 25, 2018
1 parent 8a90e6d commit 918b359
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function shufflePuzzle() {
stage.drawImage(img, piece.sx, piece.sy, pieceWidth, pieceHeight, xPos, yPos, pieceWidth, pieceHeight);
// stage.strokeRect(xPos, yPos, pieceWidth,pieceHeight);
}
startTheClock(PUZZLE_TIMEOUT);
// startTheClock(PUZZLE_TIMEOUT);
document.onmousedown = onPuzzleClick;
}

Expand All @@ -117,13 +117,8 @@ function shufflePuzzle() {
function onPuzzleClick(e) {

//takes cursor position
if(e.layerX || e.layerX == 0){
mouse.x = e.layerX - canvas.offsetLeft;
mouse.y = e.layerY - canvas.offsetTop;
} else if (e.offsetX || e.offsetX == 0){
mouse.x = e.offsetX - canvas.offsetLeft;
mouse.y = e.offsetY - canvas.offsetTop;
}
mouse.x = e.pageX - canvas.offsetLeft;
mouse.y = e.pageY - canvas.offsetTop;

currentPiece = checkPieceClicked();
if(currentPiece != null){
Expand Down Expand Up @@ -155,13 +150,8 @@ function updatePuzzle(e) {

//określanie pozycji kursora
currentDropPiece = null;
if(e.layerX || e.layerX == 0){
mouse.x = e.layerX - canvas.offsetLeft;
mouse.y = e.layerY - canvas.offsetTop;
} else if (e.offsetX || e.offsetX == 0){
mouse.x = e.offsetX - canvas.offsetLeft;
mouse.y = e.offsetY - canvas.offsetTop;
}
mouse.x = e.pageX - canvas.offsetLeft;
mouse.y = e.pageY - canvas.offsetTop;

//Podsiwetlanie kafelka, rysowanie kafelków nieprzeciąganych od nowa
stage.clearRect(0, 0, canvas.width, canvas.height);
Expand Down Expand Up @@ -248,7 +238,7 @@ function resetPuzzleAndCheckWin() {
// stage.strokeRect(gridPiece.xPos, gridPiece.yPos, pieceWidth, pieceHeight);
if(piece.xPos != gridPiece.xPos || piece.yPos != gridPiece.yPos){
gameWin = false;
console.log("piece: " + piece.xPos + ", grid: " + gridPiece.xPos);
// console.log("piece: " + piece.xPos + ", grid: " + gridPiece.xPos);
}
}
if(gameWin){
Expand Down

0 comments on commit 918b359

Please sign in to comment.