2011-10-25 51 views
0

我想洗牌图像表,我也想存储这些图像的坐标,我该怎么做?有没有其他方法可以做到这一点?我所做的是这样的在表格中洗牌图像

local alpha = {{"alpha_a"} , {"alpha_b"} , {"alpha_c"} , {"alpha_d"} , 
    {"alpha_e"} , {"alpha_f"} , {"alpha_g"} , {"alpha_h"}} 

local coordinates ={{x=092, y=470}, {x=197, y=470}, {x=302, y=470}, 
     {x=407, y=470}, {x=512, y=470}, {x=617, y=470} } 

    for i=1, #alpha do 
     local selection = table.remove(coordinates, math.random(#coordinates)) 
     print(selection.x,selection.y, #coordinates) 
     images = display.newImage(alpha[i][1]..".png") 
     images.x = selection.x 
     images.y = selection.y 
     images:addEventListener("touch",swapping) 
    end 

回答

0

这并不完全清楚你想达到什么,但我想它可能会保持图像与自己的坐标一起。

我认为实现这个逻辑的做法是重新考虑你的数据结构,并把坐标和名称到同一个表像

local alpha = {{"alpha_a",x=092, y=470} , {"alpha_b",x=197, y=470} , {"alpha_c",x=302, y=470} , {"alpha_d",x=407, y=470} , {"alpha_e",x=512, y=470}} --...