【发布时间】:2021-05-17 12:32:14
【问题描述】:
我现在就从我的情况开始。
我从https://github.com/ChrisSerpico/raycasting下载了raycast项目
这是基于这里的教程:https://lodev.org/cgtutor/raycasting.html
在我让项目开始工作、玩了一会儿并修改了一些东西之后,我目前坚持添加多个图层(基于每个图层一个地图)。我在 Internet 上阅读了很多内容,但未能实现该功能。
在这个项目中:https://github.com/Owlzy/OwlRaycastEngine
添加了多个图层,但这是通过切片完成的,我不知道如何在 Serpico 项目中实现这一点(之所以选择这个是因为那里的地板/天花板绘图效果更好)。纹理保存如下:
Texture2D canvas; // used to convert the buffer to a single texture to be drawn
Color[] buffer; // screen buffer with raw color data to be drawn
Color[][] rawData; // raw data of the individual external textures
// initialize graphics rendering objects
canvas = new Texture2D(GraphicsDevice, SCREEN_WIDTH, SCREEN_HEIGHT);
buffer = new Color[SCREEN_WIDTH * SCREEN_HEIGHT];
rawData = new Color[NUM_TEXTURES][]; //number of Textures
for (int i = 0; i < NUM_TEXTURES; i++)
{
rawData[i] = new Color[TEXTURE_WIDTH * TEXTURE_HEIGHT];
}
缓冲区在 Wallcasting 循环中以这种方式填充:
if (TEXTURE_WIDTH * texY + texX <= rawData[texNum].Length - 1)
{
buffer[SCREEN_WIDTH * y + x] = rawData[texNum][TEXTURE_WIDTH * texY + texX];
}
else //avoid crash when running into walls
{
buffer[SCREEN_WIDTH * y + x] = rawData[texNum][rawData[texNum].Length - 1];
}
最后是这样画的:
canvas.SetData<Color>(buffer);
b.Draw(canvas, new Rectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), Color.White);
代码直接来自 lodev 教程。我尝试了变量 lineHeight , texY 等等,但没有结果。纹理会被拉伸、截断,或者屏幕会产生糟糕的效果。
有人可以帮忙吗?我真的很绝望……
非常感谢!
【问题讨论】:
标签: c# layer monogame raycasting