你好,我正在尝试创建一个贴图,允许我在地图上的特定区域中特殊地放置它们。就像你在这张照片里看到的

瓷砖使用数字放置在特定的区域,我在visual上使用Monogame,我很难找到这样做的方法/解释,这不是一个容易回答的问题,因为可以给出许多选项,但是任何东西都会感激。
编辑:
此外,我正在尝试放置一个瓷砖,以建立一条道路上的单一瓷砖。
发布于 2015-03-30 07:55:24
您可以像下面这样从一个2d数组中构建这个数组,最重要的部分是绘图时的position。
x * texture.Width确保在x轴上画出一个接一个的纹理。
y * texture.Height确保将纹理线画在彼此下方的线上。
tilesPosition[y][x]包含将要绘制的瓷砖的位置(在您的例子中为0到18 )。
var textures = new Texture2D[]
{
Content.Load<Texture2D>("texture0"),
// others
Content.Load<Texture2D>("texture18")
}
int[][] tilesPosition = new int[][]
{
new[] {0, 0, 0, 0, 0, 0, 0},
// others
new[] {0, 0, 1, 2, 3, 4, 0},
// others
new[] {18, 18, 18, 18, 18, 18, 18}
};
for (int y = 0; y < tilesPosition.Length; y++)
{
for (int x = 0; x < tilesPosition[x].Length; x++)
{
var texture = textures[tilesPosition[y][x]];
Vector2 position = new Vector2(x * texture.Width,y * texture.Height)
spriteBatch.Draw(texture, position, Color.White);
}
}迭代如下所示。

https://stackoverflow.com/questions/29340485
复制相似问题