0

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.

4

1 回答 1

0

根据评论,width每个形状的实际是绘制时的两倍。所以你要做的就是把所有的宽度加起来,然后除以 2;这为您提供了形状所需的总宽度。从您要占用的屏幕上的总宽度中减去它;这为您提供了可用的空间量。然后除以形状的数量,减一;这为您提供了添加到每个形状右侧的空间量(大约,因为它可能不会完全划分;只是向下舍入)。所以每个形状的偏移量是前一个形状的偏移量,加上它的一半宽度,再加上我们刚刚计算的值。我不知道 Lua,所以我会把编码留给你。

于 2011-09-05T00:39:28.017 回答