数组中的图像,间距不正确
形状位于图像的顶部。
http://picturepush.com/public/6472916
代码如下所示:
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("i:" .. i .. " width:" .. shapesPrevArray[i - 1].width .. " x value:" .. shapesPrevArray[i - 1].x .." xoffset:" .. xOffset)
shapesPrevArray[i].x = xOffset
shapesPrevArray[i].y = 41
shapesPrevArray[i].isVisible = true
xOffset = 0
end
end
我正在尝试空间数组中的所有图像均具有相同的间距。数组中的图像具有不同的宽度。 .x 值位于形状的左上角。任何帮助将不胜感激。
The shapes are at the top of the image.
http://picturepush.com/public/6472916
The code looks like this:
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("i:" .. i .. " width:" .. shapesPrevArray[i - 1].width .. " x value:" .. shapesPrevArray[i - 1].x .." xoffset:" .. xOffset)
shapesPrevArray[i].x = xOffset
shapesPrevArray[i].y = 41
shapesPrevArray[i].isVisible = true
xOffset = 0
end
end
I'm trying to space all of the images in the array out with the same space between each image. Images in the array have different width. The .x value is at the top left corner of the shapes. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据评论,每个形状的宽度实际上是绘制时的两倍。所以你要做的就是把所有的宽度相加然后除以2;这为您提供了形状所需的总宽度。从您想要占用的屏幕上的总宽度中减去该宽度;这为您提供了可用空间量。然后将其除以形状的数量,再减一;这为您提供了添加到每个形状右侧的空间量(大约,因为它可能不会精确划分;只是向下舍入)。所以每个形状的偏移量就是前一个形状的偏移量加上其宽度的一半,再加上我们刚刚计算的值。我不懂 Lua,所以我把编码留给你。
Per the comment, the
width
of each shape is actually twice what it will be drawn as. So what you have to do is add up all the widths and divide the sum by 2; this gives you the total width needed by the shapes. Subtract this from the total width on the screen you want to take up; this gives you the amount of space available. Then divide that by the number of shapes, minus one; this gives you the amount of space to add to the right of each shape (approximately, since it probably won't divide exactly; just round down). So each shape's offset is the offset of the previous shape, plus half its width, plus the value we just calculated. I don't know Lua so I'll leave the coding to you.