数组中的图像,间距不正确

发布于 2024-12-02 19:25:04 字数 1072 浏览 2 评论 0原文

形状位于图像的顶部。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2024-12-09 19:25:04

根据评论,每个形状的宽度实际上是绘制时的两倍。所以你要做的就是把所有的宽度相加然后除以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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文