在MonoGame项目中,当我在Initialize()
方法
graphics.PreferMultiSampling = true;
graphics.ApplyChanges();
Console.WriteLine($"Device: {graphics.GraphicsDevice.Adapter.Description}");
Console.WriteLine($"Anti-aliasing: {(rasterizer.MultiSampleAntiAlias ? "YES" : "NO")}");
Console.WriteLine($"MultiSampling: {(graphics.PreferMultiSampling ? "YES" : "NO")}");
这是我的Draw
方法
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(rasterizerState: rasterizer);
DrawCheckerboard();
spriteBatch.End();
base.Draw(gameTime);
但是,当PreferMultiSampling = false
时,结果为:
这是一个干净的新项目测试,我唯一添加的是
RasterizerState rasterizer = new RasterizerState { MultiSampleAntiAlias = false };
用于SpriteBatch
spriteBatch.Begin(rasterizerState: rasterizer);
但添加/删除它并没有任何影响。
使用单像素纹理绘制棋盘格,升级。
pixel = new Texture2D(GraphicsDevice, 1, 1);
pixel.SetData(new[] { Color.White });
绘图过程(可能与问题的原因无关)看起来像这样:
void DrawCheckerboard() {
bool IsWhite(int x, int y) {
var a = x % 2 == 0;
var b = y % 2 == 0;
return a == b;
}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
var coordinates = ScaleCheckerboardCoordinatesToScreen(new Point(x, y));
spriteBatch.Draw(pixel, new Rectangle(coordinates, new Point(squareSize)), IsWhite(x, y) ? Color.White : Color.Black);
}
}
}
Point ScaleCheckerboardCoordinatesToScreen(Point coordinates) {
return new Point(offsetX + coordinates.X * squareSize, offsetY + coordinates.Y * squareSize);
}
这个问题的原因可能是哪里?
答案 0 :(得分:0)