如果我使用浮动坐标线移动我的瓷砖,它们会出现在它们之间,但是如果我使用整数则没有撕裂。我怎么解决这个问题,而不是定位他们购买。我不想通过整体来定位它们的原因是因为如果我移动一个像素的速度慢,那么移动就会变得不稳定。我使用monogame。
答案 0 :(得分:0)
尝试移动相机而不是移动瓷砖。相机可以移动浮点值,并且您的瓷砖不会撕裂,因为它们是固定位置。
这是我如何在我的旧游戏中渲染瓷砖地图的示例。我没有在这里发布所有结构,但希望你可以对你在自己的游戏中如何运作做出一些假设。
// Only render tiles that are within the view area to save significant rendering time.
// Convert the camera's view rectangle into tile indexes (by deviding by tile size).
// Add +1 for the outsides to account for the fact that this is based on the left size
// of the tile.
//
MBHEngine.Math.Rectangle view = CameraManager.pInstance.pViewRect;
Int32 startX = (Int32)MathHelper.Max((Int32)view.pLeft / mMapInfo.mTileWidth, 0);
Int32 endX = (Int32)MathHelper.Min((Int32)view.pRight / mMapInfo.mTileWidth + 1, mMapInfo.mMapWidth);
Int32 startY = (Int32)MathHelper.Max((Int32)view.pTop / mMapInfo.mTileHeight, 0);
Int32 endY = (Int32)MathHelper.Min((Int32)view.pBottom / mMapInfo.mTileHeight + 1, mMapInfo.mMapHeight);
// Loop through every tile on screen.
for (Int32 y = startY; y < endY; y++)
{
for (Int32 x = startX; x < endX; x++)
{
// Render the empty tile.
batch.Draw(
mMapInfo.mTileMap,
new Microsoft.Xna.Framework.Rectangle(
x * mMapInfo.mTileWidth, y * mMapInfo.mTileHeight, mMapInfo.mTileWidth, mMapInfo.mTileHeight),
new Microsoft.Xna.Framework.Rectangle(
mCollisionGrid[x, y].mImageIndex * mMapInfo.mTileWidth, 0, mMapInfo.mTileWidth, mMapInfo.mTileHeight),
Color.White);
}
}