Tileset for HTML5 canvas game

后端 未结 3 594
遥遥无期
遥遥无期 2021-02-10 11:34

I\'m trying to make a game in HTML5 canvas, but instead of uploading a ton of images I want to just upload one image that has all of the tiles on it. The problem is, I don\'t kn

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-10 11:57

    You can use the slicing parameters of drawImage

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

    alt text

    • 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)

提交回复
热议问题