为什么元素(建筑物)显示在错误的位置。我从基地下载后点击后使用相同的代码。
此代码我在drop element(building)之后使用。这段代码很好用。
else if (build[row] != null && build[row][col] != null) {
tilePositionY -= building.height - tile.height;
tilePositionX -= (building.width / 2) - (tile.width / 2);
context.drawImage(building, Math.round(tilePositionX), Math.round(tilePositionY), building.width, building.height);
}
此代码我从基础
下载后使用if (oldBuild[row] && oldBuild[row][col]){
tilePositionY -= building.height - tile.height;
tilePositionX -= (building.width / 2) - (tile.width / 2);
context.drawImage(building, Math.round(tilePositionX), Math.round(tilePositionY), building.width, building.height);
}
ajax请求
var oldBuild = [];
$.ajax({
type : "GET",
url : "dane.php",
async : false,
success : function(msg) {
oldBuild = msg;
}
});
dane.php
$sql = mysql_query("SELECT * FROM test");
$return=[];
while($RES = mysql_fetch_array($sql))
{
if(!isset($return[$RES['row']]))
$return[$RES['row']]=[];
$return[$RES['row']][$RES['col']]= true; //albo rodzaj budynku
}
echo json_encode($return, JSON_FORCE_OBJECT);