本文整理汇总了C++中sf::RenderWindow::GetEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::GetEvent方法的具体用法?C++ RenderWindow::GetEvent怎么用?C++ RenderWindow::GetEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderWindow
的用法示例。
在下文中一共展示了RenderWindow::GetEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showCredits
void showCredits(sf::RenderWindow& app)
{
Credits credit(app);
//Credits loop
while (app.IsOpened()) {
//Process events
sf::Event Event;
//Window closed
while (app.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
app.Close();
//Escape key pressed
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
app.Close();
}
if (credit.showCredits())
{
app.Clear();
credit.update();
app.Display();
continue;
}
else
{
break;
}
}
}
示例2: drawSplashScreen
void drawSplashScreen(sf::RenderWindow & renderWindow)
{
//renderWindow.Draw(sprite::splash);
sf::String welcome;
toSFString("You are a chicken. \n The french are advancing and \nwant to fry you with lasers.\n\n Space to shoot, Z to fire shotgun",
sf::Vector2f(200, 500),
&welcome,
sf::Color(255, 0, 0));
renderWindow.Draw(welcome);
renderWindow.Display();
sf::Event event;
bool running = true;
while (running)
{
while(renderWindow.GetEvent(event))
{
if(event.Type == sf::Event::KeyPressed
|| event.Type == sf::Event::MouseButtonPressed
|| event.Type == sf::Event::Closed )
{
return;
}
}
}
}
示例3: Show
void SplashScreen::Show(sf::RenderWindow & renderWindow)
{
sf::Image image;
if(image.LoadFromFile("images/SplashScreen.png") != true)
{
return;
}
sf::Sprite sprite(image);
renderWindow.Draw(sprite);
renderWindow.Display();
sf::Event event;
while(true)
{
while(renderWindow.GetEvent(event))
{
if (event.Type == sf::Event::KeyPressed ||
event.Type == sf::Event::MouseButtonPressed ||
event.Type == sf::Event::Closed)
{
return;
}
}
}
} // End Show
示例4: getEvents
/// This function handles any Events/Inputs thrown to the game
/// Do any input code here
/// Arguments are window => Window to register inputs from
/// THANKS TO JA_COP FOR HELPING ME OUT WITH THIS :)
void getEvents(sf::RenderWindow& window)
{
sf::Event event;
while(window.GetEvent(event))
{
switch(event.Type)
{
case sf::Event::Closed:
window.Close();
break;
case sf::Event::KeyPressed:
switch(event.Key.Code)
{
case sf::Key::Escape:
window.Close();
break;
default:
// TODO: A call to some global key handler here? ;esa
break;
}
break;
default:
// I don't know what to do here but ja_cop says this:
// Pass to input module or GUI module (placeholder)
// so do that i guess
// TODO: ADD MORE INPUTS
break;
}
}
}
示例5: handleEvents
int handleEvents(){
sf::Event event;
while(_window.GetEvent(event)){
switch(event.Type)
{
case sf::Event::KeyPressed:
switch(event.Key.Code){
case sf::Key::Escape:
quit();
break;
case sf::Key::Up:
walk += move_step_increment;
walk = std::min(walk, max_move_step);
break;
case sf::Key::Down:
walk -= move_step_increment;
walk = std::max(walk, .0);
break;
case sf::Key::Left:
rotation += rotation_step_increment;
rotation = std::min(rotation, max_rotation_step);
break;
case sf::Key::Right:
rotation -= rotation_step_increment;
rotation = std::max(rotation, -max_rotation_step);
break;
case sf::Key::Return:
rotation = 0;
walk = 0;
break;
case sf::Key::Q:
range += 10;
range = std::min(range, max_range);
updateRangeSpriteScale();
break;
case sf::Key::W:
range -= 10;
range = std::max(range, min_range);
updateRangeSpriteScale();
break;
default:
break;
} // end of key switch
break;
case sf::Event::MouseButtonPressed:
if(event.MouseButton.Button == sf::Mouse::Left){
mouseLeftPressed(event.MouseButton.X, event.MouseButton.Y);
}
break;
default:
break;
} // end of event type switch
} // end of while
return 0;
}
示例6: Run
int Splash::Run(sf::RenderWindow &win, sf::VideoMode &vMode)
{
Event events;
while(win.IsOpened())
{
while(win.GetEvent(events))
{
if(events.Type == Event::Closed)
win.Close();
if(win.GetInput().IsKeyDown(Key::Space)) return 2;
}
if(m_scripter.RunScript(&m_splashBgImg, &m_splashBgSp) == 2) return 2;
win.Clear();
win.Draw(m_splashBgSp);
win.Display();
}
return -1;
}
示例7: run
void MainMenuHandler::run(sf::RenderWindow& window) {
ImageCache mainMenuImages;
const sf::Image& logoImage = mainMenuImages.get(Path::findDataPath("graphics/logo.png"));
// Entering main menu, no game should be running.
GameHandler::instance.reset();
// Make view that is as close to 640x480 as possible and centered.
view = window.GetDefaultView();
view.Zoom(std::min(view.GetRect().GetWidth() / 640, view.GetRect().GetHeight() / 480));
view.SetCenter(view.GetHalfSize());
window.SetView(view);
window.SetFramerateLimit(30);
// Position at the top of the window.
sf::Sprite logoSprite(logoImage);
logoSprite.SetCenter(logoImage.GetWidth() / 2, 0);
logoSprite.SetPosition(window.GetView().GetRect().GetWidth() / 2, 1);
// Build the main menu GUI.
GUI::Container gui;
gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("New game", 200, 100, 240, 50, boost::bind(&MainMenuHandler::startGame, this))));
gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("Exit", 250, 170, 140, 50, boost::bind(&sf::RenderWindow::Close, boost::ref(window)))));
menuClosed = false;
while (window.IsOpened() && !menuClosed) {
sf::Event e;
if (window.GetEvent(e)) {
if (gui.handleEvent(e, window)) {
continue;
}
if (e.Type == sf::Event::Closed || (e.Type == sf::Event::KeyPressed && e.Key.Code == sf::Key::Escape)) {
window.Close();
continue;
}
} else {
window.Clear(sf::Color(0xcc, 0x66, 0x33));
window.Draw(logoSprite);
gui.draw(window);
window.Display();
}
}
}
示例8: GetMenuResponse
MainMenu::MenuResult MainMenu::GetMenuResponse(sf::RenderWindow& window)
{
sf::Event menuEvent;
while(true)
{
while(window.GetEvent(menuEvent))
{
if(menuEvent.Type == sf::Event::MouseButtonPressed)
{
return HandleClick(menuEvent.MouseButton.X,menuEvent.MouseButton.Y);
}
if(menuEvent.Type == sf::Event::Closed)
{
return Exit;
}
}
}
}
示例9: GetMenuResponse
MainMenu::MenuResult MainMenu::GetMenuResponse(sf::RenderWindow& window)
{
sf::Event menuEvent;
while(true)
{
while(window.GetEvent(menuEvent))
{
if(menuEvent.Type == sf::Event::MouseButtonPressed)
{
if(ServiceLocator::GetAudio()->IsSongPlaying())
//ServiceLocator::GetAudio()->StopAllSounds();
return HandleClick(menuEvent.MouseButton.X, menuEvent.MouseButton.Y);
}
if(menuEvent.Type == sf::Event::Closed)
{
return Exit;
}
}
}
}
示例10: Show
void SplashScreen::Show(sf::RenderWindow& renderWindow)
{
sf::Image image;
sf::Color bgColor = sf::Color(40,40,40);
//Replace this?
if (image.LoadFromFile("test.png") != true)
return;
sf::Sprite sprite(image);
cerr<<renderWindow.GetWidth()/2<<" "<< renderWindow.GetHeight()/2<<endl;
sprite.SetCenter(184/2,184/2);
sprite.SetPosition(renderWindow.GetWidth()/2 , renderWindow.GetHeight()/2);
renderWindow.Clear(bgColor);
renderWindow.Draw(sprite);
renderWindow.Display();
sf::Event event;
sf::Clock clock;
while(clock.GetElapsedTime()<3)
{
while(renderWindow.GetEvent(event))
{
if ( event.Type == sf::Event::KeyPressed
|| event.Type == sf::Event::MouseButtonPressed
|| event.Type == sf::Event::Closed)
{
renderWindow.Clear(bgColor);
return;
}
}
}
renderWindow.Clear(bgColor);
return;
}
示例11: Show
void SplashScreen::Show(sf::RenderWindow& window)
{
window.Clear(sf::Color(0,0,0));
sf::Image image;
if(image.LoadFromFile("assets/paint-wars.png") !=true)
{
return;
}
sf::Sprite sprite(image);
window.Draw(sprite);
sf::String inst = sf::String("Press any key or click the mouse to continue.");
inst.SetPosition(
Game::SCREEN_WIDTH / 2 - 300,
Game::SCREEN_HEIGHT / 2
);
window.Draw(inst);
window.Display();
sf::Event event;
while(true)
{
while(window.GetEvent(event))
{
if(event.Type == sf::Event::KeyPressed ||
event.Type == sf::Event::MouseButtonPressed ||
event.Type == sf::Event::Closed)
{
return;
}
}
}
}
示例12: Run
int MainMenu::Run(sf::RenderWindow & App)
{
while(m_Running)
{
App.Clear();
App.Draw(m_Background);
while(App.GetEvent(m_Event))
{
if(m_Event.Type == sf::Event::Closed)
{
m_Running = false;
return (-1);
}
if(m_Event.Type == sf::Event::MouseButtonPressed && m_SinglePlayerRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
{
// GO TO GAME
return 4;
}
if(m_Event.Type == sf::Event::MouseButtonPressed && m_MultiPlayerRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
{
// GO TO JOINLOBBY
return 3;
}
if(m_Event.Type == sf::Event::MouseButtonPressed && m_OptionsRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
{
// GO TO OPTIONS
return 2;
}
if(m_Event.Type == sf::Event::MouseButtonPressed && m_ExitGameRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
{
// EXIT GAME
m_Running = false;
return (-1);
}
}
ShowMainMenuLabels(App);
std::ostringstream bufor;
sf::String tdebug;
tdebug.SetFont(sf::Font::GetDefaultFont());
tdebug.SetSize(20);
tdebug.SetColor(sf::Color(255,0,0,255));
bufor << "BufforSize= " << gResMng.Get_MapSize();
tdebug.SetText(bufor.str());
App.Draw(tdebug);
App.Display();
sf::Sleep(0.01f);
} // end of while(Running)
return (-1);
}
示例13: spr
vector<Start_Items*> Start_Items::SetHair(sf::RenderWindow& App, sf::Sprite* menu)
{
vector<Start_Items*> parts;
int ids=0;
if (initalizeItems(ids,parts,menu) == 1) NULL;
else EXIT_FAILURE;
//cout << parts[0]->name << endl;
sf::Image img_spr;
img_spr.LoadFromFile("sprites/fig2t.png");
sf::Sprite spr(img_spr);
spr.SetPosition(200,210);
spr.Scale(1.5,1.5);
sf::Image i;
i.LoadFromFile("items/hair/next_button.jpg");
sf::Sprite next(i);
next.SetPosition(691,491);
vector<Start_Items*> eq2;
vector<Start_Items*> all;
sf::String hair_str;
hair_str.SetPosition(100,500);
while (App.IsOpened())
{
App.Clear();
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::MouseButtonPressed)
{
if (eq2.size() >=1 && !((Event.MouseButton.X >= 691 && Event.MouseButton.X <= 755) &&
(Event.MouseButton.Y >= 491 && Event.MouseButton.Y <=555))) eq2.clear();
for (int x=0; x<parts.size(); x++)
{
if ((Event.MouseButton.X >= parts[x]->hair.GetPosition().x && Event.MouseButton.X <= parts[x]->hair.GetPosition().x+26*(parts[x]->hair.GetScale().x)) &&
(Event.MouseButton.Y >= parts[x]->hair.GetPosition().y && Event.MouseButton.Y <= parts[x]->hair.GetPosition().y+40*(parts[x]->hair.GetScale().y)))
eq2.push_back(parts[x]);
}
if ((Event.MouseButton.X >= 691 && Event.MouseButton.X <= 755) && (Event.MouseButton.Y >= 491 && Event.MouseButton.Y <=555))
{
ids+=1;
all.push_back(eq2[0]);
if (initalizeItems(ids,parts,menu) == 2) return all;
}
}
}
//cout << ids << endl;
App.Draw(*(menu));
spr.SetSubRect(sf::IntRect(0,0,32,48));
App.Draw(spr);
if (ids>0)
{
for (int x=0; x<all.size(); x++)
{
all[x]->hair.Scale(1,1);
all[x]->hair.SetSubRect(sf::IntRect(0,0,32,48));
all[x]->hair.SetPosition(spr.GetPosition().x, spr.GetPosition().y);
App.Draw(all[x]->hair);
}
}
for (int x=0; x<eq2.size(); x++)
{
eq2[x]->hair.Scale(1,1);
eq2[x]->hair.SetSubRect(sf::IntRect(0,0,32,48));
eq2[x]->hair.SetPosition(spr.GetPosition().x, spr.GetPosition().y);
hair_str.SetText("You have selected: "+eq2[x]->name);
App.Draw(eq2[x]->hair);
App.Draw(hair_str);
}
for (int x=0; x<parts.size(); x++)
{
int wid=400+(50*(x+1));
int hei=200;
if (wid>=601)
{
hei=280;
wid=400+(50*(x-3));
}
parts[x]->hair.SetSubRect(sf::IntRect(0,0,32,47));
if (parts[x]->hair.GetScale().x != 1.5) parts[x]->hair.Scale(1.5,1.5);
parts[x]->hair.SetPosition(wid,hei);
App.Draw(parts[x]->hair);
}
App.Draw(next);
App.Display();
}
}
示例14: update
int GameScreen::update (sf::RenderWindow &app)
{
int nextScreen = myID;
float elapsedTime = app.GetFrameTime();
sf::Event event;
while (app.GetEvent(event)) // Boucle des évènements en attente
{
if (event.Type == sf::Event::Closed)
{
return EXIT;
}
else if(m_iHandler->testEvent(event, "Quit"))
{
return EXIT;
}
else if (event.Type == sf::Event::MouseMoved)
{
sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseMove.X, event.MouseMove.Y, &ConfigOptions::getView());
m_cursor.moveOnSquare(BoardAlignedSprite::toSquares(mouseCoords), false);
}
else if(m_iHandler->testEvent(event, "Up"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, -1);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(m_iHandler->testEvent(event, "Left"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(-1, 0);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(m_iHandler->testEvent(event, "Down"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, 1);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(m_iHandler->testEvent(event, "Right"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(1, 0);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(playerHasHand())
{
if(m_iHandler->testEvent(event, "Save"))
{
m_game.saveToFile(BACKUP_FILE);
}
else if(m_iHandler->testEvent(event, "Load"))
{
m_game.loadFromFile(BACKUP_FILE);
refreshAll();
}
else if (m_iHandler->testEvent(event, "LClick"))
{
sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
if(isValid(s))
clickOn(s);
else if(!m_game.hasStarted())
{
PieceType type = m_placementUI.click(mouseCoords);
if(type == NB_PIECES) //end of turn
tryAndEndTurn();
else
m_selectedType = type;
}
}
if (m_iHandler->testEvent(event, "Choose"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition());
if(isValid(s))
clickOn(s);
}
else if (m_iHandler->testEvent(event, "RClick"))
{
sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
if(!m_game.hasStarted())
remove(s);
}
else if (m_iHandler->testEvent(event, "EndTurn"))
{
tryAndEndTurn();
}
else if (event.Type == sf::Event::MouseWheelMoved)
{
if(event.MouseWheel.Delta > 0)
{
m_selectedType = m_placementUI.goUp();
}
else
{
m_selectedType = m_placementUI.goDown();
}
}
else if (m_iHandler->testEvent(event, "Rabbit"))
//.........这里部分代码省略.........
示例15: run
/**
* Méthode principale de l'écran
*
* @Param sf::RenderWindow &fenetre
* @Param Personnage &perso1
* @Param Personnage &perso2
* @Param Affichage &affichage
* @Param Carte &carteJeu
* @Son &son
*
* @Return int
*/
int EcranMenuMulti::run(sf::RenderWindow &fenetre, Personnage &perso1, Personnage &perso2, Affichage &affichage, Carte &carteJeu, Son &son)
{
sf::Event monEvent;
bool running = true;
int i = 0;
int j = 0;
int k = 0;
int l = 0;
//Chargement de l'image de fond du menu multijoueur
if (!ImageMulti.LoadFromFile("tilesets/MenuMulti.png"))
std::cout << "Erreur chargement image du menu multi" << std::endl;
//Chargement du tile pour le choix des personnages
if (!ImagePerso.LoadFromFile("tilesets/Tile_perso.jpg"))
std::cout << "Erreur chargement image du menu multi (tile perso)" << std::endl;
//Chargement du tile pour le choix de la map
if (!ImageMap.LoadFromFile("tilesets/Tile_Map.png"))
std::cout << "Erreur chargement image du menu multi (tile map)" << std::endl;
//Chargement de l'image flèche droite
if (!ImageFlecheDroite.LoadFromFile("tilesets/FlecheDroite.png"))
std::cout << "Erreur chargement image du menu multi (fleche droite) '" << std::endl;
//Chargement de l'image flèche droite
if (!ImageFlecheGauche.LoadFromFile("tilesets/FlecheGauche.png"))
std::cout << "Erreur chargement image du menu multi (fleche gauche)" << std::endl;
//Chargement de l'image pour le nombre de manches gagnantes
if (!ImageNombreManches.LoadFromFile("tilesets/Tile_NombreManches.png"))
std::cout << "Erreur chargement image du menu multi (tile nombre de manches)" << std::endl;
//Chargement des images dans les sprites
SpriteMulti.SetImage(ImageMulti);
SpriteFlecheDroite1.SetImage(ImageFlecheDroite);
SpriteFlecheDroite2.SetImage(ImageFlecheDroite);
SpriteFlecheDroite3.SetImage(ImageFlecheDroite);
SpriteFlecheDroite4.SetImage(ImageFlecheDroite);
//Position des différents sprites
SpriteFlecheDroite1.SetPosition(230, 450);
SpriteFlecheDroite2.SetPosition(230, 620);
SpriteFlecheDroite3.SetPosition(630, 390);
SpriteFlecheDroite4.SetPosition(590, 587);
SpriteFlecheGauche1.SetImage(ImageFlecheGauche);
SpriteFlecheGauche2.SetImage(ImageFlecheGauche);
SpriteFlecheGauche3.SetImage(ImageFlecheGauche);
SpriteFlecheGauche4.SetImage(ImageFlecheGauche);
SpriteFlecheGauche5.SetImage(ImageFlecheGauche);
SpriteFlecheGauche1.SetPosition(50, 450);
SpriteFlecheGauche2.SetPosition(50, 620);
SpriteFlecheGauche3.SetPosition(420, 390);
SpriteFlecheGauche4.SetPosition(5, 695);
SpriteFlecheGauche5.SetPosition(455, 587);
SpritePerso1.SetImage(ImagePerso);
SpritePerso1.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
SpritePerso2.SetImage(ImagePerso);
SpritePerso2.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
SpriteMap.SetImage(ImageMap);
SpriteMap.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEMAP, TAILLEIMAGEMAP));
SpriteNombreManches.SetImage(ImageNombreManches);
SpriteNombreManches.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEMANCHES, TAILLEIMAGEMANCHES));
SpritePerso1.SetPosition(115, 425);
SpritePerso2.SetPosition(115, 595);
SpriteMap.SetPosition(485, 350);
SpriteNombreManches.SetPosition(520, 585);
while(running)
{
//Tant que la fenêtre contient des évènements
while(fenetre.GetEvent(monEvent))
{
if (monEvent.Type == sf::Event::Closed)
return (ECRAN_QUITTER); // On quitte le jeu
if((monEvent.Type == sf::Event::MouseButtonPressed) && (monEvent.MouseButton.Button == sf::Mouse::Left))
{
//Cas ou on clique sur la fleche précédant
if(monEvent.MouseButton.X > SpriteFlecheGauche4.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheGauche4.GetPosition().x + TAILLEFLECHE)
{
if(monEvent.MouseButton.Y > SpriteFlecheGauche4.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheGauche4.GetPosition().y + TAILLEFLECHE)
{
//On affiche le Menu Principal
//.........这里部分代码省略.........