代碼:繪製畫布內部的圖像
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