用于HTML5帆布游戏的Tileset [英] Tileset for HTML5 canvas game

查看:135
本文介绍了用于HTML5帆布游戏的Tileset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在HTML5画布上制作游戏,但不想上传大量图片,而只想上传一张包含所有图块的图片。问题是,我不知道如何只显示图像的一部分。基本上我想要做Google用这张图片做的事情:(MDC)

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 know how to make only one part of the image show up. Basically I want to do what Google does with this image: http://www.google.com/images/srpr/nav_logo27.png except with fixed height/width tiles. Can someone explain to me how to do this? Also, if it's different in canvas than in a regular html page without canvas, how would I do it in canvas?

解决方案

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)

这篇关于用于HTML5帆布游戏的Tileset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆