immagini spaziali in una matrice in modo uniforme su, tenendo conto delle diverse larghezze immagine

StackOverflow https://stackoverflow.com/questions/7302754

  •  22-10-2019
  •  | 
  •  

Domanda

local xOffset = 0

for i = 1, levelPacks[prevCurrentLevelPack][prevCurrentLevel].ammount do

    if i == 1 then --setup first one

        shapesPrevArray[i].x = 30
        shapesPrevArray[i].y = 41
        shapesPrevArray[i].isVisible = true

    end

    if i > 1 then --setup the rest

        --width of previous one plus the x value of the previous one to make them next to eachother.
        xOffset = shapesPrevArray[i - 1].width + shapesPrevArray[i - 1].x
        print("offset: " .. xOffset)
        shapesPrevArray[i].x = xOffset    
        shapesPrevArray[i].y = 41
        shapesPrevArray[i].isVisible = true
        xOffset = 0

    end

    i = i + 1

end


i:2 width:60 x value:30 xoffset:90
i:3 width:40 x value:90 xoffset:130
i:4 width:50 x value:130 xoffset:180
i:5 width:70 x value:180 xoffset:250

Qualcuno può darmi una mano per favore? Non riesco a capire perché questo bit non li sta spaziatura fuori.

xOffset = shapesPrevArray [i - 1] .width + shapesPrevArray [i - 1] .x

Se qualcuno potrebbe spiegare il motivo per cui non è e mi punto nella giusta direzione, sarei grato.

Grazie.

È stato utile?

Soluzione

Si dovrebbe rimuovere i = i + 1

Una numerico per ha la seguente sintassi:

for var=exp1,exp2,exp3 do
  something
end

Questo ciclo eseguirà qualcosa per ogni valore di var da exp1 a exp2, utilizzando EXP3 il passo di incremento var. Questa terza espressione è facoltativa; quando assente, Lua assume uno come il valore di passo.

http://www.lua.org/pil/4.3.4.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top