Xcode 在使用 C++ 构建后删除 SDL2 标头

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

我正在关注一个正在制作彩色窗口的视频,该窗口将建立在最终成为游戏的基础上。 (https://www.youtube.com/watch?v=44tO977slsU&list=PLhfAbcv9cehhkG7ZQK0nfIGJC_C-wSLrx)

项目有3个文件。

main.cpp:

#include "Game.hpp"


Game * game = nullptr;

int main(int argc, const char * argv[]) {
    
    game = new Game();
    
    game -> init("Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, false);
    
    while (game -> running()) {
        game -> handleEvents();
        game -> update();
        game -> render();
    }
    
    game -> clean();
    
    return 0;
}

游戏.cpp:

#include "Game.hpp"

Game::Game()
{}

Game::~Game()
{}

void Game::init(const char *title, int xpos, int ypos, int width, int height, bool fullscreen)
{
    int flags = 0;
    
    if (fullscreen) {
        flags = SDL_WINDOW_FULLSCREEN;
    }
    
    /*
     Initialisation Check
     Creating Window
     */
    if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
    {
        std::cout << "Subsystems Initialised.\n";
        
        window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
    
        //Window Creation Chacking
        if (window) {
            std::cout << "Window Created.\n";
        }
        
        //Creating Renderer
        renderer = SDL_CreateRenderer(window, -1, 0);
        
        //Renderer Creation Chacking
        if (renderer) {
            SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
            std::cout << "Renderer Created.\n";
        }
        
        isRunning = true;
    }
    
    else {
        isRunning = false;
    }
}

void Game::update()
{}

void Game::render()
{
    SDL_RenderClear(renderer);
    //This is where we add stuff to the renderer
    SDL_RenderPresent(renderer);
    
}

void Game::handleEvents()
{
    SDL_Event event;
    SDL_PollEvent(&event);
    switch (event.type) {
        case SDL_QUIT:
            isRunning = false;
            break;
            
        default:
            break;
    }
    
}

void Game::clean()
{
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    std::cout << "Game Cleaned.\n";
}

游戏.hpp:

#ifndef Game_hpp
#define Game_hpp

#include <SDL2/SDL.h>
#include <iostream>

class Game{
    
public:
    Game();
    ~Game();
    
    void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
    
    void handleEvents();
    void update();
    void render();
    void clean();
    
    bool running() {return isRunning;}
    
private:
    bool isRunning;
    SDL_Window * window;
    SDL_Renderer * renderer;
    
};




#endif /* Game_hpp */

在线

#include <SDL2/SDL.h>
我得到以下错误:
'SDL2/SDL.h' file not found
和以下警告:
Did not find header 'SDL.h' in framework 'SDL2' (loaded from '/Volumes/MyDisk/MyProfile/Library/Developer/Xcode/DerivedData/2D_GameEngine-cmipcirpykhqlddnnupbpbazpoai/Build/Products/Debug')

每当我运行 Xcode 构建并运行的程序时,它也会从 SDL.framework 中删除 SDL 的头文件。

我真的看到它在建造后立即将它们移除。

我已经无数次将头文件移动到它应该的文件,但它仍然被删除

c++ xcode macos sdl-2
© www.soinside.com 2019 - 2024. All rights reserved.