【问题标题】:Passing window and texture to a function将窗口和纹理传递给函数
【发布时间】:2014-03-12 19:08:04
【问题描述】:

我开始在 SFML 中编写基于图块的游戏并遇到了这个问题。我认为我在将纹理和窗口传递给函数时做错了。请帮助我;)。对不起我的英语。

代码:

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

using namespace std;
using namespace sf;

class Tile
{

int number,colision;
Sprite sTile;
public:

//void add(int n,int c,Texture &tTile,int x,int y,int x2,int y2)   {number=n;colision=c;sTile.setTexture(&tTile);sTile.setTextureRect(IntRect(x,y,x2,y2));}     
int getcolision(){return colision;}
int getnumber(){return number;}
void drawTile(int x,int y,RenderWindow &window){sTile.setPosition(x,y);window.draw(sTile);}


};

int g_map[200][200];


int main()
{   for(int x=0;x<200;x++){for(int y=0;y<200;y++){g_map[x][y]=0;}}

RenderWindow window( VideoMode( 800, 600 ), "SFML2.1-window" );

Tile tile[100];
Texture tTile;
tTile.loadFromFile("textures.bmp");
tile[0].drawTile(0,0,window);

while( window.isOpen() )
{
    Event event;
    while( window.pollEvent( event ) )
    {
        if( event.type == Event::Closed )
             window.close();

    } //while
    window.clear();


    window.display();
} //while
return 0;
}

错误: C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x136): 未定义引用 _imp___ZN2sf6StringC1EPKcRKSt6locale' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x15c): undefined reference toimpZN2sf9VideoModeC1Ejjj' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x1a0): 未定义引用_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x1ed): undefined reference to_imp_ZN2sf7TextureC1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x238): 未定义对 _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x293): undefined reference toimpZN2sf6Window5closeEv' 的引用 C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x2ab): 未定义引用_imp___ZN2sf6Window9pollEventERNS_5EventE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x2dd): undefined reference to_imp_ZN2sf5ColorC1Ehhhh' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x2f8): 未定义对 _imp___ZN2sf12RenderTarget5clearERKNS_5ColorE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x30a): undefined reference toimpZN2sf6Window7displayEv' 的引用 C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x319): 未定义引用_imp___ZNK2sf6Window6isOpenEv' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x335): undefined reference to_imp_ZN2sf7TextureD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x369): 未定义引用 _imp___ZN2sf12RenderWindowD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x393): undefined reference toimpZN2sf12RenderWindowD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x421): 未定义引用_imp___ZN2sf7TextureD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x461): undefined reference to_imp_ZN2sf12RenderWindowD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text$ZN2sf8DrawableD2Ev[_ZN2sf8DrawableD2Ev]+0xfffff6d2):未定义对_imp___ZTVN2sf8DrawableE' c:\dev-cpp\mingw32\mingw32\bin\ld.exe C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o: bad reloc address 0xe in section.text$ZN2sf8DrawableD2Ev[_ZN2sf8DrawableD2Ev]' c:\dev-cpp\mingw32\mingw32\bin\ld.exe 最终链接失败:无效操作 C:\Users\Maks\Documents\dev\sfml\Nowy 文件夹 (2)\tile\collect2.exe [错误] ld 返回 1 退出状态

【问题讨论】:

    标签: function sfml


    【解决方案1】:

    您似乎没有提供良好的链接器设置,这是将您的可执行文件与 SFML 的 DLL 链接所必需的。

    请认真关注tutorial

    【讨论】:

    • 哦,我刚刚重新加载了文件,现在可以正常使用了。谢谢! :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2010-12-16
    • 2017-02-11
    相关资源
    最近更新 更多