对象不能在SDL (c++)中工作
objects not working in SDL (C++)
我正在用c++做一个简单的游戏,用SDL作为我的API。我把我的图像分割函数放在一个单独文档的类中,这样它在我的主文件上就不会那么混乱了。但是,当我尝试使用类的对象调用函数时,IDE说我正在对函数进行未定义的引用。下面是主文件:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "imageBlitingFunctions.h"
#include <iostream>
#include <string>
#include <sstream>
int screenW = 640;
int screenH = 480;
int screenBPP = 32;
SDL_Surface* window = SDL_SetVideoMode(screenW, screenH, screenBPP, SDL_SWSURFACE);
imageBlitingFunctions IBFobject;
SDL_Surface* background1;
SDL_Surface* player1;
int main(int argc, char* args[])
{
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
background1 = IBFobject.loadIMG("background.png");
player1 = IBFobject.loadIMG("swordtest.png");
IBFobject.blitIMG(0, 0, window, background1, 0, 0, 1000, 1000);
IBFobject.blitIMG(0, 0, window, player1, 100, 0, 100, 300);
SDL_FreeSurface(background1);
SDL_FreeSurface(player1);
SDL_Quit();
return 0;
}
这是类的头文件:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include <iostream>
#include <string>
#ifndef IMAGEBLITINGFUNCTIONS_H
#define IMAGEBLITINGFUNCTIONS_H
class imageBlitingFunctions
{
public:
SDL_Surface *loadIMG(std::string filename);
void blitIMG(int pX, int pY, SDL_Surface *window, SDL_Surface *image, int cpX, int cpY, int cpH, int cpW);
SDL_Surface *loadText(int red, int blue, int green, std::string fontname, int fontSize, std::string text);
};
#endif // IMAGEBLITINGFUNCTIONS_H
这里是类:
#include "imageBlitingFunctions.h"
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include <iostream>
#include <string>
SDL_Surface* imageBlitingFunctions::loadIMG(std::string filename)
{
SDL_Surface *img = IMG_Load(filename.c_str());
SDL_Surface *imgOPT = SDL_DisplayFormat(img);
SDL_FreeSurface(img);
return imgOPT;
}
void imageBlitingFunctions::blitIMG(int pX, int pY, SDL_Surface *window, SDL_Surface *image, int cpX, int cpY, int cpH, int cpW)
{
SDL_Rect positionIMG;
positionIMG.x = pX;
positionIMG.y = pY;
SDL_Rect clipP;
clipP.x = cpX;
clipP.y = cpY;
clipP.h = cpH;
clipP.w = cpW;
SDL_BlitSurface(image, &clipP, window, &positionIMG);
SDL_Flip(window);
}
SDL_Surface* imageBlitingFunctions::loadText(int red, int blue, int green, std::string fontname, int fontSize, std::string text)
{
int color1 = red;
int color2 = blue;
int color3 = green;
SDL_Color textColor = {color1, color2, color3};
TTF_Font *font1 = TTF_OpenFont(fontname.c_str(), fontSize);
SDL_Surface *message1 = TTF_RenderText_Solid(font1, text.c_str(), textColor);
return message1;
}
任何帮助都会很感激。
对函数的未定义引用意味着链接器找不到该函数的定义。函数的定义是你放在代码"这里是类:"(也许你叫它imageBlitingFunctions.cpp或类似的东西?)所以问题是你的IDE找不到这个文件。
要解决这个问题,你需要修复项目配置
相关文章:
- QSqlquery prepare()和bindvalue()不工作
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- 有人能解释一下为什么下界是这样工作的吗C++的
- ExtractIconEx:可以工作,但偶尔会崩溃
- C++中的memset函数工作不正常
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 链表c++插入,所有情况都已检查,但没有任何工作
- 为什么stream::忽略未按预期工作