我在AS3中创建了一个我需要保存到数据库的tilemap,系统工作正常。当用户创建一个帐户时,会自动为他们创建一个地图(它始终是相同大小的地图,有树木,岩石等11x11)。
[18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5],
如何将此保存到mysqli数据库然后获取信息并将其返回到AS3脚本?我知道如何从AS3发布,我知道如何从页面获取信息。我已经将整个数组保存在一个名为tileMap的列下,然后当我尝试从表中查询tileMap时...没有返回任何内容。是因为我使用的是[ ]
大括号吗?我真的不知道如何展示这个。
答案 0 :(得分:0)
你可以序列化/反序列化你的数据,恕我直言保存JSON格式的数据库数据会很好,因为它很容易在Object()中转换这样的数据 因此也在数组中。)
//this function converts data from Array to Object, we need Object for easy JSON conversation afterwards
function toObject(array:Array):Object
{
var obj:Object = {};
for (var i:int = 0; i < array.length; ++i)
{
obj[i] = array[i];
}
return obj;
}
//this converts Object To Array
function toArray(obj:Object):Array
{
var arr:Array = [];
for (var i in obj)
{
if (obj.hasOwnProperty(i))
{
arr.push(obj[i]);
}
}
return arr;
}
//it's you array
var arr:Array = [[18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17], [7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5]];
var jsonString:String = JSON.stringify(toObject(arr)); //we got JSON string which for example could be saved as TEXT data in MySQL via PHP
var onceMoreArray:Array=toArray(JSON.parse(jsonString)); //We can convert JSON string back to array
希望这种方法有所帮助。
答案 1 :(得分:0)
从矩阵中创建一个字符串。
[1,0,2],
[2,3,4],
[0,1,5]
成为
1:0:2|2:3:4|0:1:5
要阅读,您可以使用拆分功能,首先使用&#39; |&#39;然后用&#39;:&#39;