使用SDL在C ++中创建图形类

问题描述 投票:0回答:1

我正在尝试用C ++创建一个洞穴故事克隆的游戏窗口,所以首先,我创建下面的头文件,之后,我去创建类文件。当我完成该类时,我一直收到参数类型为sdl_window和sdl_render的参数类型不完整的错误。如果有人能帮助我弄清楚我做错了什么。

到Graphics.h

#ifndef GRAPHICS.h

#define GRAPHICS.h

struct SDL_window;
struct SDL_render;

class Graphics {
    public:
        Graphics();
        ~Graphics();
    private:
        SDL_window* window = NULL;
        SDL_render* render = NULL;
};

#endif

Graphics.cpp

#include <SDL.h>

#include "graphics.h"


/* Graphics class
* Holds all information dealing with graphics for the game
*/

Graphics::Graphics() {
    SDL_CreateWindowAndRenderer(640, 480, 0, &window, &render);
    SDL_SetWindowTitle(window, "Cavestory");
}

Graphics::~Graphics() {
    SDL_DestroyWindow(window);
}
c++ visual-studio sdl
1个回答
5
投票

问题是您声明自己的类型与SDL类型无关。重写类以使用适当的类型:

#include <SDL.h>

class Graphics {
  public:
    Graphics();
    ~Graphics();
  private:
    SDL_Window *   window = nullptr;
    SDL_Renderer * render = nullptr;
};
© www.soinside.com 2019 - 2024. All rights reserved.