首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >瓷砖布局错误

瓷砖布局错误
EN

Stack Overflow用户
提问于 2016-03-03 19:25:27
回答 1查看 54关注 0票数 0

我创建了一个int数组的级别。

代码语言:javascript
复制
using UnityEngine;
using System.Collections;

public class Level1 : MonoBehaviour 
{
    int[][] level = new int[][]
    {
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}
    };
    public Transform tile00;
public Transform tile16;
public Transform tile38;

int rows = 12;
int cols = 32;

void Start () 
{

    BuildLevel ();
}

void BuildLevel(){
    int i, j;

    GameObject dynamicParent = GameObject.Find ("DynamicObjects");
    for(i=0; i<rows; i++)
    {
        for(j=0; j<cols; j++)
        {
            Transform toCreate = null;
            Debug.Log (i + "  ,  " + j + "   " + level[i][j]);
            if (level[i][j] == 0)
                toCreate = tile00;
            if (level[i][j] == 83)
                toCreate = tile38;;
            if (level[i][j] == 16)
                toCreate = tile16;

            Vector3 v3 = new Vector3(16-j, 6-i, 0);
            Transform newObject = Instantiate(toCreate, v3, Quaternion.identity) as Transform;
            newObject.parent = dynamicParent.transform;
        }
    }
}
  }

输出屏幕如下所示:

瓷砖是50×50。我改变了瓷砖的尺寸,改变了X和Y的位置。我什么都试过了,但是我发现没有solution.Could,你给我一个ideea,好吗?

对于水平瓷砖,我想要获得的布局是(图像是用油漆处理的):

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-05 14:38:48

最有可能的答案是因为这一行

代码语言:javascript
复制
Vector3 v3 = new Vector3(16-j, 6-i, 0);

你说你的图像是50x50Px。假设您没有将像素更改为您的sprite的单位属性,这将使这些图像在X&Y轴上占用0.5个单元的空间。

现在,在你的计算中,这是正在发生的事情。

迭代1- (i = 0,j= 0)。位置= Vector3(16,6,0)

迭代2- (i = 0,j= 1)。位置= Vector3(15,6,0)

..。

迭代33 -(i = 1,j= 0)。位置= Vector3(16,5,0)

现在,迭代1和迭代2之间的X值的差异是1单位。我们已经确定这些雪碧将只占用0.5单位,因为他们的大小。

在迭代1和迭代33的Y轴上也是一样的。差1单位,每幅图像只占0.5个单位。

因此,要么将图像更改为100 x 100 px,要么将像素更改为单位。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35781217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档