0

我有这个代码:

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 的新手,我已经被困在这里很长时间了。

谢谢

4

1 回答 1

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
于 2013-06-18T21:42:03.380 回答