在阵列的图像,不能正确地间隔 [英] Images in an array, not spacing correctly

查看:110
本文介绍了在阵列的图像,不能正确地间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的形状是在图像的顶部。

The shapes are at the top of the image.

http://picturepush.com/public/6472916

在code是这样的:

    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值是在形状的左上角。任何帮助将是AP preciated。

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.

推荐答案

每注释中,宽度每个形状其实是两次将被绘制成。所以,你必须做的是添加了所有的宽度和除以2的总和;这给你的形状所需的总宽度。从要占用屏幕上的总宽度减去这一点;这给你的可用空间量。然后除以形状的数量,减一;这给你的空间添加到每个形状的右侧(约,因为它可能不会准确划分;只需向下取整)的数量。因此,每个形状的偏移previous形状是偏移量,加上一半的宽度,再加上价值,我们刚刚计算。我不知道这样的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.

这篇关于在阵列的图像,不能正确地间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆