간단한 텍스트 게임을 만들려고 노력하고 있지만 이상한 문제가 발생했습니다. SDL_KEYDOWN을 사용하여 사용자 키보드에서 입력을 받도록 클래스를 설정했습니다. 함수 check_event()
이 호출되면 키보드 입력을 폴링하고 버튼에 대한 문자열을 반환하는 루프를 실행합니다. 이상한 점은 키를 누르는 것은 효과가 없다는 것입니다. 코드는 내 while 루프에서 멈추지 만, 내 함수가 전혀 효과가없는 것처럼 보입니다. 여기SDL 키보드 입력이 트리거되지 않음
#include <iostream>
#include <fstream>
#include <SDL.h>
#include "SDL_ttf.h"
#include "input.h"
using namespace std;
Input input;
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
return 1;
}
cout << "Welcome to Hero V1.0!" << endl; //intro stuff
cout << "Written By: Jojo" << endl;
cout << endl;
cout << "1) New Game" << endl;
cout << "2) Continue Game" << endl;
while (true) {
string event = input.check_event();
if(event == "1"){
cout << "Test" << flush;
}
}
SDL_Quit();
return 0;
}
그리고
#include <iostream>
#include <SDL.h>
#include "Input.h"
using namespace std;
string Input::check_event() {
while (SDL_PollEvent(&event)) {
if(event.type == SDL_KEYDOWN){
switch(event.key.keysym.sym){
case SDLK_1:
return "1";
}
}
}
return "null";
}
이 어떤 도움을 주시면 더 좋구요 통화 당 내 입력 클래스는 다음과 같습니다
여기 내 주요 코드입니다.
당신은 창을 만든 것 같지 않습니다. SDL은 (많은 이유로, 문제가 있거나 불가능할 수도있는) 전체 시스템 입력 잡기 기능을 가지고 있지 않습니다. 텍스트 게임 키 누르기의 경우 stdin (read, getch, ...)에서 읽어야합니다. – keltar