我是中级unity开发人员,还在学习过程中。我坚持使用变换游戏对象。我知道它有位置,旋转和缩放属性,但是,我正在跟随一个俄罗斯方块的克隆来扩大我的技能,我真的很难理解。请不要认为这只是俄罗斯方块游戏,我有困难的时候这种情况下的游戏,其中有网格系统在2维。
我将在下面分享一种代码,我真的不完全理解发生了什么,只是本能地理解。
开发人员按照如下步骤操作:创建转换、网格数组,并尝试将块数据分配给此网格数组,然后根据移动的块更新网格等,这很酷。但是我不能理解代码发生了什么,因为我不能在我的脑海中塑造这个过程。
这里有一个代码示例;
// will be called from tetromino script
public void UpdateGrid(Tetromino tetromino)
{
for (int y = 0; y < gridHeight; y++)
{
for (int x = 0; x < gridWidth; x++)
{
// if there is a current existing tetromino in the grid coordinate
if (grid[x, y] != null) // registered mino at this position
{
// check to is if the tetromino is there
// if the parent transform is the tetromino transform that is send as parameter
if (grid[x,y].parent == tetromino.transform)
{
grid[x, y] = null; // updating the grid
}
}
}
}
// updates our grid
foreach (Transform mino in tetromino.transform)
{
Vector2 pos = Round(mino.position);
if (pos.y < gridHeight)
{
// storing mino with transform in that position
grid[(int)pos.x, (int)pos.y] = mino;
}
}
}在这个代码示例中,我必须理解什么?这里的网格代表什么?一个点?一个空的游戏对象?这里发生了什么?
他是否将变换" mino“指定为mino块对象的引用?
我真的很难使用Transform网格系统,很多游戏都有这种网格系统,比如《2048》或者《粉碎》游戏,或者俄罗斯方块游戏等等。
你能帮助我理解变换网格和场景中的mino块之间的关系吗?
我真的在努力学习游戏开发,并且花了很多时间去学习。我感觉我正在成长,但有时我会在路上遇到困难。网格系统在游戏中跟踪移动的对象或块是非常重要的,我想对它有一个纯粹的理解。
发布于 2019-03-25 02:03:51
好的,混淆术语会增加你的困惑。
根据它的想法,它有一个名为grid的数组来计算物体是否可以移动-虽然你没有展示网格是如何定义的,但它将具体说明它是如何定义的,所以它可能会变换,grid = new Transformx,y其中x和y是网格的大小,x和y是网格的大小,它考虑的是表示游戏区域的物理网格的宽度和高度。
简而言之,在俄罗斯方块中,Transform mino in tetromino.transform获取所有子组件并逐个遍历它们。通常将构成俄罗斯方块形状的4个块称为mino,其中,由于最终形状是Tetromino,请参阅https://en.wikipedia.org/wiki/Tetromino
使用一个数组来决定是否所有的方块都可以向下移动1,这比尝试移动一个对象并让unity决定它是否适合要容易得多。
https://stackoverflow.com/questions/55326678
复制相似问题