首页 > 解决方案 > “Release”中的方法无法正常工作

问题描述

我是 C++ 新手,所以我遇到了问题。在“调试”模式下,我得到了这张照片,这是正确的:所有的墙壁都是透明的

所有色彩斑斓的墙壁都应该是透明的

但是在“发布”模式下,我得到了这个:

有些墙是透明的,有些不是,这是不正确的

我确定我搞砸了我的墙类并创建了对象:

std::vector<Wall> glassWalls = {
    Wall(Vec2(2.0f, 1.0f), Vec2(2.0f, 2.0f),true,255, 0, 0,  0.5f),
    Wall(Vec2(2.0f, 2.0f), Vec2(3.0f, 1.0f),true, 255, 0, 0, 0.5f),
    Wall(Vec2(3.0f, 1.0f), Vec2(2.0f, 1.0f), true, 255, 0, 0, 0.5f),
    Wall(Vec2(1.0f, 3.0f), Vec2(3.0f, 7.0f), true, 0, 255, 0, 0.5f),
    Wall(Vec2(3.0f, 7.0f), Vec2(3.0f, 4.0f), true, 0, 255, 0, 0.5f),
    Wall(Vec2(3.0f, 4.0f), Vec2(1.0f, 3.0f), true, 0, 255, 0, 0.5f),
    Wall(Vec2(5.0f, 7.0f), Vec2(6.0f, 7.0f), true, 255, 255, 0, 0.5f),
    Wall(Vec2(6.0f, 7.0f), Vec2(6.0f, 6.0f), true, 255, 255, 0, 0.5f),
    Wall(Vec2(6.0f, 6.0f), Vec2(5.0f, 7.0f), true, 255, 255, 0, 0.5f),
    Wall(Vec2(5.0f, 1.0f), Vec2(5.0f, 4.0f), true, 255, 0, 255, 0.5f),
    Wall(Vec2(5.0f, 4.0f), Vec2(7.0f, 5.0f), true, 255, 0, 255, 0.5f),
    Wall(Vec2(7.0f, 5.0f), Vec2(5.0f, 1.0f), true, 255, 0, 255, 0.5f)
};

这是我的方法,应该通过 dist 返回颜色

int red = std::min((int)(std::max((-colorR / WALL_VISIBILITY * dist + colorR + emmision * 255.0f), 0.0f)), colorR);
    int green = std::min((int)(std::max((-colorG / WALL_VISIBILITY * dist + colorG + emmision * 255.0f), 0.0f)), colorG);
    int blue = std::min((int)(std::max((-colorB / WALL_VISIBILITY * dist + colorB + emmision * 255.0f), 0.0f)), colorB);
    if (isGlass) {
        sf::Color newCol(red, green, blue, std::max(std::min((int)(transparency * 255), 255), 0));
        return newCol;
    }
    else {
        float k = std::max(std::min(transparency, 1.0f), 0.0f);
        return sf::Color((int)(red * k), (int)(green * k), (int)(blue * k));
    }

标签: c++visual-studiodebuggingsfmlrelease

解决方案


molbdnilo是对的,我搞砸了我的构造函数。类有字段“isGlass”,构造函数也有“isGlass”。


推荐阅读