gpt4 book ai didi

c++ - 基于 2D 图 block 的游戏,当我用相机放大时,图 block Sprite 之间会出现间隙吗?

转载 作者:行者123 更新时间:2023-11-30 02:08:48 28 4
gpt4 key购买 nike

我正在使用 D3DXSPRITE 方法将我的 map 图 block 绘制到屏幕上,我刚刚添加了一个缩放功能,当您按住向上箭头时会放大,但注意到您现在可以看到图 block 之间的间隙,这是一些屏幕截图

每个图 block 的正常大小 (32x32)

enter image description here

放大(您可以看到瓷砖之间的白色间隙)

enter image description here

缩小(甚至更糟!)

enter image description here

这是我用来翻译和扩展世界的代码片段。

D3DXMATRIX matScale, matPos;

D3DXMatrixScaling(&matScale, zoom_, zoom_, 0.0f);
D3DXMatrixTranslation(&matPos, xpos_, ypos_, 0.0f);

device_->SetTransform(D3DTS_WORLD, &(matPos * matScale));

这是我绘制的 map ,(瓦片在瓦片 vector 的 vector 中..我还没有完成剔除)

LayerInfo *p_linfo = NULL;
RECT rect = {0};
D3DXVECTOR3 pos;
pos.x = 0.0f;
pos.y = 0.0f;
pos.z = 0.0f;

for (short y = 0;
y < BottomTile(); ++y)
{
for (short x = 0;
x < RightTile(); ++x)
{
for (int i = 0; i < TILE_LAYER_COUNT; ++i)
{
p_linfo = tile_grid_[y][x].Layer(i);

if (p_linfo->Visible())
{
p_linfo->GetTextureRect(&rect);

sprite_batch->Draw(
p_engine_->GetTexture(p_linfo->texture_id),
&rect, NULL, &pos, 0xFFFFFFFF);
}
}
pos.x += p_engine_->TileWidth();
}
pos.x = 0;
pos.y += p_engine_->TileHeight();
}

最佳答案

你的纹理索引是错误的。 0,0,32,32 不是正确的值 - 它应该是 0,0,31,31。 256 像素的纹理图集中从零开始的索引将产生 0 到 255 的值,而不是 0 到 256,而 32x32 纹理应该产生 0,0,31,31。在这种情况下,错误像素的颜色取决于右侧和底部下一个纹理的颜色。

关于c++ - 基于 2D 图 block 的游戏,当我用相机放大时,图 block Sprite 之间会出现间隙吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6162836/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com