【发布时间】:2016-05-08 20:28:51
【问题描述】:
在给定的情况下:
- 一张 32x32 的 Tile 地图即将用 C# 在 monogame 中绘制。
- 每个纹理都是 64x64 像素。
- 只有一种纹理(即一个 .png 文件)不断重复自己来填充地图。
- 每个图块都是 Tile.cs 类中的对象
示例 1:
创建一个包含要绘制的一个纹理的静态/抽象类,以便每个平铺对象在绘制时都可以使用它。
public void Draw(){
//Texture.GrassTexture is from the static class
tile.Draw(Textures.GrassTexture);
}
示例 2:
另一种方法是在创建新对象时为每个图块设置一个纹理变量。
Texture2D tileTexture;
public Tile(Texture texture){
tileTexture = texture;
}
绘制瓦片时,可以使用tileTexture变量。
示例 3:
绘制图块时发送纹理作为每个图块的参数。
public void Draw(Texture2D texture){
tile.draw(texture)
}
从性能的角度来看,哪些示例是最佳实践?欢迎任何其他想法!
代码是为这篇文章编写的。
【问题讨论】: