在我的2D等距引擎中,我有以下类:
maps(variable)/layers(variable)/cubes(variable)/sides(6)/points(4)/coordinates(3)
- 每个立方体有6个面,每个面有4个点(1个点=1个坐标(x,y,z))。
- 我可以用同样大小的立方体创建任意大小的地图。
文件夹:
assets/numTexture/numLight.png
我使用numTexture和numLight计算一个数字,该数字是我在数组中加载的所有numLight.png(纹理)的纹理编号。
但是纹理出现了问题:
我在层类中定义我的立方体坐标:
for(int J = 0; J < mapSize; J++)
{
for(int I = 0; I < mapSize; I++)
{
x = (J - I) * (cubeSize/2);
y = (J + I) * (cubeSize/4);
c = new cube(cubeSize, x, y, z, I, J);
cs.push_back(*c);
}
}
在side.cpp文件中,我使用了一个关于sideType的switch语句(如果它是顶部、左侧等,则会定义我的点的坐标不同)。 对于每个立方体,我有6个这样的switch语句(这里只提供数据)。
就像这样:
switch(typeSide)
{
case 0://DOWN_SIDE
light = 0;
tmp_x = x + (size/2);
tmp_y = y + (size/2);
p0 = new point(tmp_x, tmp_y, tmp_z);
tmp_x = x + size;
tmp_y = y + (3 * (size/4));
p1 = new point(tmp_x, tmp_y, tmp_z);
tmp_x = x + (size/2);
tmp_y = y + size;
p2 = new point(tmp_x, tmp_y, tmp_z);
tmp_x = x;
tmp_y = y + (3 * (size/4));
p3 = new point(tmp_x, tmp_y, tmp_z);
break;
//ETC. ....
还有一个显示地图的 display() 函数:
void GRAPHICS_HANDLER::display()
{
x = 0;
y = 0;
if(maps.size() > 0 && maps[0].layers().size() > 0)//If there is any map and layers to display
{
for(int l = 0; l <= getCurrentLayerID(); l++)//FOR EACH LAYER, WE STOP TO THE CURRENT EDITED LAYER
{
for(unsigned int c = 0; c < maps[currentMapID].layers()[l].cubes().size(); c++)//FOR EACH CUBES
{
if(maps[currentMapID].layers()[l].cubes()[c].getFlat())//If flat mode is enabled: to draw texture like grass, etc...(cf. screen): We draw only one side
{
for(unsigned int p = 0; p < 4; p++)//FOR EACH POINTS
{
//--------------------------------------------------------------------------------------LOAD MAP-----------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------CUBE CLICK DETECTION::TEXTURE CHANGE--------------------------------------------------//
if(cubeClicked || brushMode && currentSelectedCube > -1 && currentSelectedCube < maps[currentMapID].layers()[maps[currentMapID].currentLayerId()].cubes().size())
{
maps[currentMapID].layers()[maps[currentMapID].currentLayerId()].cubes()[currentSelectedCube].setTexture(currentSelectedTexture);
if(!brushMode)
cubeClicked = false;
}
//--------------------------------------------------------------------------CUBE CLICK DETECTION::TEXTURE CHANGE--------------------------------------------------//
//--------------------------------------------------------------------------------------CURSOR - NOT WORKING-----------------------------------------------------------------------------------------------------------------//
//...
//--------------------------------------------------------------------------------------CURSOR - NOT WORKING-----------------------------------------------------------------------------------------------------------------*/
if(enableOffset)
{
x = maps[currentMapID].layers()[l].cubes()[c].sides()[0]->pointPosition(p)[0] + offsetLeft;//it's like doing something like point[p].x + offset left
y = maps[currentMapID].layers()[l].cubes()[c].sides()[0]->pointPosition(p)[1] + offsetTop;
}
else
{
x = maps[currentMapID].layers()[l].cubes()[c].sides()[0]->pointPosition(p)[0];//it's like doing something like point[p].x + offset left
y = maps[currentMapID].layers()[l].cubes()[c].sides()[0]->pointPosition(p)[1];
}
points[p].position = sf::Vector2f(x, y);
points[p].texCoords = sf::Vector2f(x, y);
//--------------------------------------------------------------------------------------GRID-----------------------------------------------------------------------------------------------------------------//
//GRID DISPLAY //MISS AN EDGE .
isoGrid[p].position = points[p].position;
isoGrid[p].color = sf::Color(195, 195, 195, gridOpacity);
//--------------------------------------------------------------------------------------GRID-----------------------------------------------------------------------------------------------------------------//
maps[currentMapID].layers()[l].cubes()[c].sides()[0]->setLight(5);
textureEntryNumber = (maps[currentMapID].layers()[l].cubes()[c].sides()[0]->getTexture() - 1) * 9 + (maps[currentMapID].layers()[l].cubes()[c].sides()[0]->getLight() - 1);//WRONG
//--------------------------------------------------------------------------------------GRID-----------------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------LOAD MAP-----------------------------------------------------------------------------------------------------------//
}
//--------------------------------------------------------------------------------------DISPLAY MAP-----------------------------------------------------------------------------------------------------------//
if(grid && maps[currentMapID].layers()[l].cubes()[c].sides()[0]->getTexture() <= 1)//IF GRID = TRUE OR TEXTURE LESS OR EQUAL TO 1 => DISPLAY GRID
{
if(l == maps[currentMapID].currentLayerId())
{
window->draw(isoGrid);
}
}
else if(maps[currentMapID].layers()[l].cubes()[c].sides()[0]->getTexture() > 1)//IF THERE IS ANY TEXTURE TO DISPLAY(>1) => DISPLAY TEXTURE
{
window->draw(points, &textures[textureEntryNumber]);
}
//--------------------------------------------------------------------------------------DISPLAY MAP-----------------------------------------------------------------------------------------------------------//
}
else
{
for(unsigned int s = 0; s < 6; s++)//FOR EACH SIDES(side number will always be 6, no need to make this dynamic
{
for(unsigned int p = 0; p < 4; p++)//FOR EACH POINTS
{
//--------------------------------------------------------------------------------------LOAD MAP-----------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------CUBE CLICK DETECTION::TEXTURE CHANGE--------------------------------------------------//
if(cubeClicked || brushMode && currentSelectedCube > -1 && currentSelectedCube < maps[currentMapID].layers()[maps[currentMapID].currentLayerId()].cubes().size())
{
maps[currentMapID].layers()[maps[currentMapID].currentLayerId()].cubes()[currentSelectedCube].setTexture(currentSelectedTexture);
if(flatMode)
maps[currentMapID].layers()[maps[currentMapID].currentLayerId()].cubes()[currentSelectedCube].setFlat(true);
else
maps[currentMapID].layers()[maps[currentMapID].currentLayerId()].cubes()[currentSelectedCube].setFlat(false);
if(!brushMode)
cubeClicked = false;
}
//--------------------------------------------------------------------------CUBE CLICK DETECTION::TEXTURE CHANGE--------------------------------------------------//
//--------------------------------------------------------------------------------------CURSOR - NOT WORKING-----------------------------------------------------------------------------------------------------------------//
//...
//--------------------------------------------------------------------------------------CURSOR - NOT WORKING-----------------------------------------------------------------------------------------------------------------*/
if(enableOffset)
{
x = maps[currentMapID].layers()[l].cubes()[c].sides()[s]->pointPosition(p)[0] + offsetLeft;//it's like doing something like point[p].x + offset left
y = maps[currentMapID].layers()[l].cubes()[c].sides()[s]->pointPosition(p)[1] + offsetTop;
}
else
{
x = maps[currentMapID].layers()[l].cubes()[c].sides()[s]->pointPosition(p)[0];//it's like doing something like point[p].x + offset left
y = maps[currentMapID].layers()[l].cubes()[c].sides()[s]->pointPosition(p)[1];
}
points[p].position = sf::Vector2f(x, y);
points[p].texCoords = sf::Vector2f(x, y);
//--------------------------------------------------------------------------------------GRID-----------------------------------------------------------------------------------------------------------------//
//GRID DISPLAY //MISS AN EDGE
if(s ==3)
{
isoGrid[p].position = points[p].position;
isoGrid[p].color = sf::Color(195, 195, 195, gridOpacity);
}
//--------------------------------------------------------------------------------------GRID-----------------------------------------------------------------------------------------------------------------//
textureEntryNumber = (maps[currentMapID].layers()[l].cubes()[c].sides()[s]->getTexture() - 1) * 9 + (maps[currentMapID].layers()[l].cubes()[c].sides()[s]->getLight() - 1);//WRONG
//--------------------------------------------------------------------------------------GRID-----------------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------LOAD MAP-----------------------------------------------------------------------------------------------------------//
}
//--------------------------------------------------------------------------------------DISPLAY MAP-----------------------------------------------------------------------------------------------------------//
if(grid && maps[currentMapID].layers()[l].cubes()[c].sides()[s]->getTexture() <= 1)//IF GRID = TRUE OR TEXTURE LESS OR EQUAL TO 1 => DISPLAY GRID
{
if(l == maps[currentMapID].currentLayerId())
{
window->draw(isoGrid);
}
}
else if(maps[currentMapID].layers()[l].cubes()[c].sides()[s]->getTexture() > 1)//IF THERE IS ANY TEXTURE TO DISPLAY(>1) => DISPLAY TEXTURE
{
window->draw(points, &textures[textureEntryNumber]);
}
//--------------------------------------------------------------------------------------DISPLAY MAP-----------------------------------------------------------------------------------------------------------//
}
}
}
}
}
window->display();
}
滚动此处以查看评论和标签
问题:
- 只有具有细节的纹理才会变大,单色纹理没有问题(可能是顶点绑定在一起,即使来自不同的
sf ::VertexArray 。
注意:像maps / layers / cubes等类都只是数据。
应该在屏幕上显示的Textures(numLIght)图像如下所示:
编辑:当图片只是一种颜色而没有细节时,纹理可以工作:
我不再知道我的代码有什么问题了。 也许我会重新编写display()函数...