Imágenes espaciales en una matriz de igual, teniendo en cuenta diferentes anchos de imagen
Pregunta
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
¿Puede alguien ayudarme por favor? No puedo averiguar por qué este bit no los está espaciando.
xoffset = ShapesPrevarray [i - 1] .Width + ShapesPrevArray [i - 1] .x
Si alguien pudiera explicar por qué no lo es y me señala en la dirección correcta, estaría agradecido.
Gracias.
Solución
Deberías quitar i = i + 1
Un numérico para tiene la siguiente sintaxis:
for var=exp1,exp2,exp3 do something end
Ese bucle ejecutará algo para cada valor de VAR de Exp1 a Exp2, usando exp3 como el paso para incrementar VAR. Esta tercera expresión es opcional; Cuando está ausente, Lua asume uno como valor paso.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow