在lua中获得不同的坐标

时间:2013-06-18 21:13:19

标签: lua corona

我有这段代码:

local function createBlocks()
    local rowcount = 8
    local colcount = 4

    local blockWidth = display.contentWidth / (colcount*4)
    local blockHeight = display.contentWidth / (rowcount*2)

    local row
    local col
    local pan = 3
    local i=0
    for row = 1, rowcount do
            for col = 1, colcount do
                    local x = (col - 1) * blockWidth + pan
                    local y = (row + 1) * blockHeight + pan
                    local random= math.random(1,6)

                    random = revisarTres(i, random)

                    print (random)
                    print ("primeras")
                    print (x)
                    print (y)
                    block[i] = display.newImage(images[random], x, y)
                    block[i].value= random     
                    block[i]:addEventListener("touch", blockTouch)
                    i=i+1
            end
    end
    print ("coordenadas")
    for i=0,31 do
        print (i)
        print (block[i].x)
        print (block[i].y)
    end    

end

为什么我得到不同的x和y值?

print (block[i].x)
print (x)

print (block[i].y)
print (y)

希望你能帮助我,我是lua的新手,我已经被困在这里很久了。

谢谢

1 个答案:

答案 0 :(得分:2)

试试这个:

local image = display.newImage(images[random], 0, 0)
image.x = x
image.y = y
image.value = random     
image:addEventListener("touch", blockTouch)
block[i] = image