使用sf :: Text和sf :: Font时未解析的外部符号

时间:2013-01-21 23:14:37

标签: c++ text sfml

我正在使用sfml 2.0创建一个文本类,并且在尝试构建时遇到链接器错误。这是错误:

Error   1   error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sf::Font const & __cdecl sf::Font::getDefaultFont(void)" (__imp_?getDefaultFont@Font@sf@@SAAEBV12@XZ) referenced in function "public: void __cdecl Text::create(class sf::RenderWindow &,char *,char *,float,float,unsigned int,enum style,int,int,int)" (?create@Text@@QEAAXAEAVRenderWindow@sf@@PEAD1MMIW4style@@HHH@Z) C:\Facepunch Pacman Project\Faceman\Text.obj    Faceman

这是text.h:

#ifndef TE_TEXT
#define TE_TEXT

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

enum style { bold, italic, underlined };

class Text {

    public: 
        void create(sf::RenderWindow &window,
                    char* string, 
                    char* fontpath, 
                    float positionx, 
                    float positiony,
                    unsigned int size,
                    style textstyle,
                    int red, 
                    int green, 
                    int blue);

        void setString();
        void setFont();
        void setPosition();
        void setSize();
        void setColor(int red, int green, int blue);

        Text operator==(Text t);
        Text operator!=(Text t);

        sf::Rect<int> textrect;

        void setRect();

    private:
        char* getString();
        char* getFont();
        float getPosition();    
        unsigned int getSize();
        sf::Vector3i getColor();

        sf::IntRect getRect();
};

#endif

Text.cpp(UNFINISHED):

#include <Source/Text/Text.h>

void Text::create(sf::RenderWindow &window, char* string, char* fontpath, float positionx, float positiony, unsigned int size, 
                    style textstyle, int red, int green, int blue) {

    sf::Font font;
    font.loadFromFile(fontpath);

    sf::Text text(string);
    text.setFont(font);

    text.setCharacterSize(size);

    text.setPosition(positionx, positiony);

    sf::Color color(red, green, blue);
    text.setColor(color);

    switch (textstyle)
    {
        case bold:
        {
            text.setStyle(sf::Text::Bold);
            break;
        }

        case italic:
        {
            text.setStyle(sf::Text::Italic);
            break;
        }

        case underlined:
        {
            text.setStyle(sf::Text::Underlined);
            break;
        }
    }

    window.draw(text);
}

显示主菜单功能(这不是新功能,我之前一直在使用它)

Menu::MenuResult Menu::showMMenu(sf::RenderWindow &window) {

    sf::Texture texture;
    texture.loadFromFile("Source/Images/MenuBG.png");

    sf::Sprite MMenuSprite;
    MMenuSprite.setTexture(texture);

    Text playText;

    MenuItem playButton;
    playButton.buttonrect.top = 283;
    playButton.buttonrect.height = 130;
    playButton.buttonrect.left = 0;
    playButton.buttonrect.width = WINDOW_WIDTH;
    playButton.action = Play;

    MenuItem optionsButton;
    optionsButton.buttonrect.top = 414;
    optionsButton.buttonrect.height = 130;
    optionsButton.buttonrect.left = 0;
    optionsButton.buttonrect.width = WINDOW_WIDTH;
    optionsButton.action = Options;

    MenuItem exitButton;
    exitButton.buttonrect.top = 549;
    exitButton.buttonrect.height = 130;
    exitButton.buttonrect.left = 0;
    exitButton.buttonrect.width = WINDOW_WIDTH;
    exitButton.action = Exit;

    menuItems.push_back(playButton);
    menuItems.push_back(optionsButton);
    menuItems.push_back(exitButton);

    window.draw(MMenuSprite);
    playText.create(window, "start", "Source/Text/Fonts/BOOKOS.ttf", 514, 352, 65, bold, 0, 0, 0);
    window.display();

    return getMenuResponse(window);
}

我可能没有正确获取字体文件路径,因为getDefaultFont是没有指定字体的时候。

0 个答案:

没有答案