Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 1.27 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. HTML5 Canvas Cropping in Chrome (performance issue)
  2. function drawMap()
  3. {
  4.  
  5. row = Math.floor(canvasOriginY / 3000);
  6. col = Math.floor(canvasOriginX / 3000);
  7.  
  8. remainderX = Math.floor(canvasOriginX % 3000);
  9. remainderY = Math.floor(canvasOriginY % 3000);
  10.  
  11. pixelsShowingX = Math.floor(3000 - remainderX);
  12. pixelsShowingY = Math.floor(3000 - remainderY);
  13.  
  14. pixelsMissingX = Math.floor(canvas.width() - pixelsShowingX);
  15. pixelsMissingY = Math.floor(canvas.height() - pixelsShowingY);
  16.  
  17.     // top-left image (always)
  18. context.drawImage(mapImages[row][col], remainderX, remainderY, pixelsShowingX, pixelsShowingY, 0, 0, pixelsShowingX, pixelsShowingY);
  19.  
  20.     // top-right image (if needed)
  21. if (pixelsMissingX > 0)
  22.     context.drawImage(mapImages[row][(col+1)], 0, remainderY, pixelsMissingX, pixelsShowingY, pixelsShowingX, 0, pixelsMissingX, pixelsShowingY);
  23.  
  24.     // bottom-left image (if needed)
  25. if (pixelsMissingY > 0)
  26.     context.drawImage(mapImages[(row+1)][col], remainderX, 0, pixelsShowingX, pixelsMissingY, 0, pixelsShowingY, pixelsShowingX, pixelsMissingY);
  27.  
  28.     // bottom-right image (if needed)
  29. if (pixelsMissingX > 0 && pixelsMissingY > 0)
  30.     context.drawImage(mapImages[(row+1)][(col+1)], 0, 0, pixelsMissingX, pixelsMissingY, pixelsShowingX, pixelsShowingY, pixelsMissingX, pixelsMissingY);
  31.     }