我正在编写一些javascript来从数组中创建x和y coodinates,所以我有这个代码:
var map1 = [
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,gg,
];
for (var i=0; i<map1.length; i++) {
if (i > 16) {
dy = Math.floor(i / 15) * 16;
}
dx = i * 16
while (dx >= 240) {
dx = dx - 240;
}
}
代码工作得非常好,除了坐标0,1和1,1不起作用?这些坐标使用此页面here上的主体构建一个包含16px块的画布。 dx
和dy
符合此等式,ctx.drawImage(tileset, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
谢谢!
答案 0 :(得分:0)
不确定这是否有帮助 - 但控制台中的以下代码段似乎为所有职位提供了正确的结果。您是否可以解释一下您期望的输出与您获得的实际输出相比?
var map1 = new Array(225);
var dx, dy;
for (var i=0; i<map1.length; i++) {
if (i > 16) {
dy = Math.floor(i / 15) * 16;
}
dx = i * 16
while (dx >= 240) {
dx = dx - 240;
}
console.log(dx + ',' + dy); //Seems to print all positions ok
}