我開始在SFML中編寫基於tile的遊戲,並且遇到了這個問題。我想我在將紋理和窗口傳遞給函數時出錯了。請幫助我;)並且對不起爲我的英語。將窗口和紋理傳遞給一個函數
代碼:
#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:\用戶\瑪克斯\應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本+ 0x136):未定義參照_imp___ZN2sf6StringC1EPKcRKSt6locale' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x15c): undefined reference to
小鬼ZN2sf9VideoModeC1Ejjj ' C:\用戶\瑪克斯\應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本+量0x1A0):未定義參照_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x1ed): undefined reference to
_imp _ZN2sf7TextureC1Ev' C:\用戶\瑪克斯\應用程序數據\本地\ Temp \ ccoLih4f.o SFMLproj.cpp :(。text + 0x238):undefined參考_imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x293): undefined reference to
小鬼ZN2sf6Window5closeEv ' C:\用戶\瑪克斯\應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本+ 0x2ab):未定義參照_imp___ZN2sf6Window9pollEventERNS_5EventE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x2dd): undefined reference to
_imp _ZN2sf5ColorC1Ehhhh' C:\用戶\瑪克斯\ 。應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本+爲0x2f8):未定義參照_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x30a): undefined reference to
小鬼ZN2sf6Window7displayEv」 C:\用戶\瑪克斯\應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp 。:(文本+ 0x319):未定義參照_imp___ZNK2sf6Window6isOpenEv' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x335): undefined reference to
_imp _ZN2sf7TextureD1Ev」 C:\用戶\瑪克斯\應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本+ 0x369):未定義參照_imp___ZN2sf12RenderWindowD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x393): undefined reference to
小鬼ZN2sf12RenderWindowD1Ev ' C:\用戶\瑪克斯\應用程序數據\本地\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本+ 0x421):未定義參照_imp___ZN2sf7TextureD1Ev' C:\Users\Maks\AppData\Local\Temp\ccoLih4f.o SFMLproj.cpp:(.text+0x461): undefined reference to
_imp _ZN2sf12RenderWindowD1Ev' C:\用戶\瑪克斯\應用程序數據\ 。地方\ TEMP \ ccoLih4f.o SFMLproj.cpp :(文本$ 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退出狀態
哦,我只是重新加載文件,現在它工作得很好。謝謝! :d – user3412301