代码:绘制画布内部的图像
function DrawLevel1() {
Pos = 1;
w = 84;
h = 84;
x = 28;
y = 28;
for (i = 0; i < cw; i += 28) { /// use +=
ctx.drawImage(tankImg,
(Pos - 1) * w, /// x of source (use 0-based indexes)
0, /// y of source
w, /// width of source
h, /// height of source
i, /// x in destination (visible canvas)
y, /// y, width and height of the resulting
w, h); /// image
x += 28;
y += 28;
}
}
DrawLevel1();
图像:
http://oi62.tinypic.com/148yf7.jpg http://oi62.tinypic.com/148yf7.jpg
帆布:<canvas id="MyCanvas" width="400" height="400"></canvas>
什么,我试图做的基本上是借鉴第一灰瓦一直画布cw
.notice的宽度的第一行我不能使用平铺阵列并绘制它,这个函数并没有画任何东西,我想不出为什么有人能帮我请
jsfiddle:http://jsfiddle.net/seekpunk/B2nUs/36/
使用'我+ = 28'而不是'i + 28'在你的循环中。 – Sebastian
我没有看到'cw'是在哪里定义的,它是你的循环的退出条件。这似乎很重要。你还没有在你的循环中递增'i' - 那么'i + = 28'(或更长的形式,'i = i + 28')怎么样? – Krease
我更新了我的代码,请检查小提琴它没有绘制任何东西 – Sora