Rodrigo López
Rodrigo López

Reputation: 225

Getting differen coordinates in lua

I have this code:

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

Why I get a differen x and y value?

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

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

Hope you can help me, I'm new with lua and I have been stuck here a long time.

Thank you

Upvotes: 0

Views: 418

Answers (1)

vovahost
vovahost

Reputation: 36017

Try this:

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

Upvotes: 2

Related Questions