2014년 7월 1일 화요일

[일기] SDL 이벤트 다루기 틀. 내용 없음.

Message-driven.

Handling Events 라는 주제로 학습했다.

SDL_PollEvent 함수를 호출하면 되는데, 익숙한 반복문 형태가 나타나게 된다.

메시지 가져오고 처리하고를 무한 반복.

위 함수의 인자는 SDL_Event 이다.

아래는 튜토리얼 사이트의 예제 코드.

while (SDL_PollEvent(&e)){

if (e.type == SDL_QUIT)
quit = true;

if (e.type == SDL_KEYDOWN)
quit = true;

if (e.type == SDL_MOUSEBUTTONDOWN)
quit = true;
}

좀 더 완성된 형태라는 예제 코드.

//구조

SDL_Event e;
bool quit = false;
while (!quit){
while (SDL_PollEvent(&e)){
if (e.type == SDL_QUIT)
quit = true;
if (e.type == SDL_KEYDOWN)
quit = true;
if (e.type == SDL_MOUSEBUTTONDOWN)
quit = true;
}
//장면 렌더링
SDL_RenderClear(renderer);
renderTexture(image, renderer, x, y);
SDL_RenderPresent(renderer);
}

댓글 없음:

댓글 쓰기