我正在construct2 中构建一个高分板,并试图正确布置字符。
为了做到这一点,我在 c2 中创建了一个数组,并使用 AJAX 从我的网络服务器上保存的 php 脚本中以 JSON 字符串的形式返回数据。然后,这些数据将用于填充数组,然后我将使用它来填写我的 SpriteFonts。理论上很简单。
这是返回 JSON 字符串的 php 文件:
if ($result = $mysqli->query($sql)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
$array = array(
array
(
'name' => $row['pName'],
'score' => $row['score']
));
echo json_encode($array);
}
/* free result set */
$result->free();
exit();
}
这将返回以下内容:
[{"name":"developer","score":"56"}]
[{"name":"Terrry","score":"34"}]
[{"name":"Numero_Uno","score":"20"}]
[{"name":"Thomasin :)","score":"18"}]
[{"name":"ThriftyButStillNifty","score":"18"}]
[{"name":"Perfect","score":"17"}]
[{"name":"bah","score":"17"}]
[{"name":"EvilEdna","score":"16"}]
[{"name":"type here","score":"16"}]
[{"name":"Slaine","score":"14"}]
要在 C2 中使用,字符串需要采用以下格式:
{"c2array":true,
"size":
[2,2,1],
"data":
[
[["John"],[23]],
[["Terry"],[43]]
]
}
我该如何从他人那里创造一个?