Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在列表迭代器中获取sf::Text属性 我正在用SFML做一个C++的小游戏。按下TAB按钮时,屏幕右侧会出现一个带有四个按钮的小菜单。我创建了一个class按钮,在类中我有一个sf::Text属性。这是我用来绘制菜单的代码 void DrawRightSideMenu(RenderWindow &win) { window.draw(rectInGameMenu); for (list<Button>::iterator currentButton = rightSideMenuButtons.begin(); currentButton != rightSideMenuButtons.end(); currentButton++) { win.draw(*currentButton); Text buttonTextToDraw = currentButton->GetButtonText(); //Crash here win.draw(buttonTextToDraw); } }_C++_Visual Studio_Sfml - Fatal编程技术网

无法在列表迭代器中获取sf::Text属性 我正在用SFML做一个C++的小游戏。按下TAB按钮时,屏幕右侧会出现一个带有四个按钮的小菜单。我创建了一个class按钮,在类中我有一个sf::Text属性。这是我用来绘制菜单的代码 void DrawRightSideMenu(RenderWindow &win) { window.draw(rectInGameMenu); for (list<Button>::iterator currentButton = rightSideMenuButtons.begin(); currentButton != rightSideMenuButtons.end(); currentButton++) { win.draw(*currentButton); Text buttonTextToDraw = currentButton->GetButtonText(); //Crash here win.draw(buttonTextToDraw); } }

无法在列表迭代器中获取sf::Text属性 我正在用SFML做一个C++的小游戏。按下TAB按钮时,屏幕右侧会出现一个带有四个按钮的小菜单。我创建了一个class按钮,在类中我有一个sf::Text属性。这是我用来绘制菜单的代码 void DrawRightSideMenu(RenderWindow &win) { window.draw(rectInGameMenu); for (list<Button>::iterator currentButton = rightSideMenuButtons.begin(); currentButton != rightSideMenuButtons.end(); currentButton++) { win.draw(*currentButton); Text buttonTextToDraw = currentButton->GetButtonText(); //Crash here win.draw(buttonTextToDraw); } },c++,visual-studio,sfml,C++,Visual Studio,Sfml,这是在创建游戏窗口时调用的void函数中。下面是我在类按钮中使用的方法: Button::Button(int inFontSize, string inFontButton) { fontSize = inFontSize; fontButton.loadFromFile(inFontButton); } void Button::SetButtonText(string inButtonText) { buttonText.setString(inButtonTex

这是在创建游戏窗口时调用的void函数中。下面是我在
类按钮中使用的方法:

Button::Button(int inFontSize, string inFontButton)
{
    fontSize = inFontSize;
    fontButton.loadFromFile(inFontButton);
}

void Button::SetButtonText(string inButtonText)
{
    buttonText.setString(inButtonText);
    buttonText.setFont(fontButton);
    buttonText.setCharacterSize(fontSize);
    buttonText.setColor(Color(255, 255, 255));
}
这些是函数正在使用的方法<代码>按钮文本
是一个
文本
属性
fontButton
是一个
Font
属性。希望这能对你们有所帮助。

检查这些:

  • 确保您的文本字体设置正确
  • 给你的文本加上颜色
  • 在渲染之前给它一个字符串
我的引擎提供了一个功能,可以向游戏中添加文本:

void Actor::addRenderedElement(sf::Text * txt, const char * font_name, const char* text, sf::Color color)
{
    if (checkGameData()) {
        sf::Font* _font = gamedata->getFont(font_name);
        if (_font != nullptr) {
            txt->setFont(*_font);
            txt->setString(text);
            txt->setColor(color);
            renderedShapes.push_back(txt);
        }
        else
            std::cout << "Invalid font name " << font_name << " for " << name << std::endl;
    }
}
检查以下各项:

  • 确保您的文本字体设置正确
  • 给你的文本加上颜色
  • 在渲染之前给它一个字符串
我的引擎提供了一个功能,可以向游戏中添加文本:

void Actor::addRenderedElement(sf::Text * txt, const char * font_name, const char* text, sf::Color color)
{
    if (checkGameData()) {
        sf::Font* _font = gamedata->getFont(font_name);
        if (_font != nullptr) {
            txt->setFont(*_font);
            txt->setString(text);
            txt->setColor(color);
            renderedShapes.push_back(txt);
        }
        else
            std::cout << "Invalid font name " << font_name << " for " << name << std::endl;
    }
}

谢谢,我今晚回家后会试试的。是的,我可能会切换到英文版哈哈哈!我确保我的字体加载正确,文本有颜色,有字符串,但仍然不好。经过进一步研究,我发现这很可能是指针的问题。我会继续寻找解决方案,或者只是改变我的做事方式。我需要更多的代码来找出问题所在。谢谢,我今晚回家后会试试。是的,我可能会切换到英文版哈哈哈!我确保我的字体加载正确,文本有颜色,有字符串,但仍然不好。经过进一步研究,我发现这很可能是指针的问题。我要么继续寻找解决方案,要么改变我的做事方式。我需要更多的代码来找出问题所在
win.draw(currentButton->GetButtonText());