Tileset for HTML5 canvas game

匆匆过客 提交于 2019-12-03 08:18:18
gblazex

You can use the slicing parameters of drawImage

drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)

  • sx, sy: left and top offset of the part to be sliced
  • sWidth, sHeight: dimensions of the part to be sliced
  • dx, dy: left and top offset for the image on the canvas to be rendered at
  • dWidth, dHeight: image dimensions on the canvas

More info at: Using images - Slicing (MDC)

Take a look at SpriteJS https://github.com/batiste/sprite.js/blob/master/sprite.js there the work is based on offset at the moment of drawing the sprite from a single picture.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!