[SFML] 윈도우 이벤트
윈도우 이벤트
윈도우 이벤트들을 다루는 법들을 알아보겠습니다..
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(512,512), "SFML TUTORIAL", sf::Style::Close | sf::Style::Resize);
while (window.isOpen())
{
sf::Event evnt;
while (window.pollEvent(evnt))
{
switch (evnt.type)
{
case sf::Event::Closed:
window.close();
break;
case evnt.Resized:
std::cout << "New window Width: " << evnt.size.width << "New window Height: " << evnt.size.height << std::endl;
//printf("New Window width: %i New Window height: %i\n", evnt.size.width, evnt.size.height);
break;
}
}
}
return 0;
}
switch 문안에서의 코드를 보면
switch (evnt.type)
{
case sf::Event::Closed: //sf::이벤트 사용
window.close();
break;
case evnt.Resized: //미리 정의해둔 sf::Event evnt 사용
std::cout << "New window Width: " << evnt.size.width << "New window Height: " << evnt.size.height << std::endl;
//printf("New Window width: %i New Window height: %i\n", evnt.size.width, evnt.size.height);
break;
}
이렇게 사용할 수도 있습니다.
Leave a comment