当前位置: 首页>>代码示例>>C++>>正文


C++ RenderWindow::draw方法代码示例

本文整理汇总了C++中sf::RenderWindow::draw方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::draw方法的具体用法?C++ RenderWindow::draw怎么用?C++ RenderWindow::draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::RenderWindow的用法示例。


在下文中一共展示了RenderWindow::draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: menu

void menu()
{
	int x, y;
	bool exit = false, high = false;
		if(!font.loadFromFile("ethnocentric rg.ttf"))
	{
		//error...
	};
		window.clear();
	sf::RectangleShape menuSquare(sf::Vector2f(550, 450));
	menuSquare.setFillColor(sf::Color(75, 75, 75));
	menuSquare.setOutlineThickness(4);
    menuSquare.setOutlineColor(sf::Color(50, 50, 50));
	menuSquare.setPosition(25, 25);

	sf::RectangleShape play(sf::Vector2f(80, 40));
	play.setFillColor(sf::Color(255, 0, 0));
	play.setOutlineThickness(4);
    play.setOutlineColor(sf::Color(255, 50, 0));
	play.setPosition(100, 350);

	playButton.setString("Play");
	playButton.setFont(font);
	playButton.setCharacterSize(20);
	playButton.setColor(sf::Color(30, 30, 30));
	playButton.setPosition(100, 357);

		sf::RectangleShape High(sf::Vector2f(90, 40));
	High.setFillColor(sf::Color(255, 0, 0));
	High.setOutlineThickness(4);
    High.setOutlineColor(sf::Color(255, 50, 0));
	High.setPosition(300, 350);

	HighButton.setString("High\nScores");
	HighButton.setFont(font);
	HighButton.setCharacterSize(15);
	HighButton.setColor(sf::Color(30, 30, 30));
	HighButton.setPosition(300, 350);

	snake.setString("SNAKE 2.0");
	snake.setFont(font);
	snake.setCharacterSize(50);
	snake.setColor(sf::Color(30, 30, 255));
	snake.setPosition(80, 75);

    CreatedBy.setString("Created by\nBrandon Aderholdt\nJanuary 10th, 2014");
	CreatedBy.setFont(font);
	CreatedBy.setCharacterSize(15);
	CreatedBy.setColor(sf::Color(30, 30, 70));
	CreatedBy.setPosition(140, 200);

	window.clear();
	while(true){
		sf::Event event;
		  while(window.pollEvent(event)) {
			  if(event.type == sf::Event::Closed)
				  window.close();

			 if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
				 sf::Vector2i localPosition = sf::Mouse::getPosition(window);
				 x = localPosition.x;
				 y = localPosition.y;
				 if((x > 100) && (x < 180) && (y < 390) && (y > 350))
				 {
					exit = true;
				 }
				 if((x > 300) && (x < 390) && (y < 390) && (y > 350))
				 {
					 high = true;
				 }
		       }
	         }
		 
		  	  window.draw(menuSquare);
			  window.draw(High);
		      window.draw(HighButton);
			  window.draw(play);
			  window.draw(playButton);
			  window.draw(snake);
			  window.draw(CreatedBy);
		      window.display();

			  if(high == true){
				  highScores();
				  window.clear();
				  high = false;
				  	HighButton.setString("High\nScores");
	HighButton.setFont(font);
	HighButton.setCharacterSize(15);
	HighButton.setColor(sf::Color(30, 30, 30));
	HighButton.setPosition(300, 350);

	snake.setString("SNAKE 2.0");
	snake.setFont(font);
	snake.setCharacterSize(50);
	snake.setColor(sf::Color(30, 30, 255));
	snake.setPosition(80, 75);

	playButton.setString("Play");
	playButton.setFont(font);
//.........这里部分代码省略.........
开发者ID:aderholdtb,项目名称:Snake-First-Ever-Project,代码行数:101,代码来源:Main.cpp

示例2: draw

void TeleportToArtifactRoom::draw(sf::RenderWindow& mainWindow){
	mainWindow.draw(sprite);
}
开发者ID:Easihh,项目名称:laughing-avenger,代码行数:3,代码来源:TeleportToArtifactRoom.cpp

示例3: draw

void Tile::draw(sf::RenderWindow& window)
{
    window.draw(_sprite);
}
开发者ID:JustPowell,项目名称:Project_C,代码行数:4,代码来源:Tile.cpp

示例4: draw

void GUIMenu::draw(sf::RenderWindow &window)
{
	for (std::vector<sf::Text>::iterator it = text.begin(); it != text.end(); it++)
		window.draw(*it);
}
开发者ID:vincenthugues,项目名称:snake-sfml,代码行数:5,代码来源:GUIMenu.cpp

示例5: draw

void particle_system::draw(sf::RenderWindow &window, sf::View view)
{
	window.setView(view);
	window.draw(va);
	window.setView(window.getDefaultView());
}
开发者ID:usey11,项目名称:particles,代码行数:6,代码来源:particle.cpp

示例6: Draw

//tell the render window to draw the shape
void Bug::Draw(sf::RenderWindow &w) {
	w.draw(m_shape);
}
开发者ID:niallarshad,项目名称:project,代码行数:4,代码来源:Bug.cpp

示例7: Run


//.........这里部分代码省略.........
	vector<string> players;

	std::string choosePlayerText = "Wpisz nazwe gracza";
	sf::Text choosePlayerLabel(choosePlayerText, font, 50);
	choosePlayerLabel.setColor(sf::Color(255, 255, 255, 255));
	float choosePlayerPosX = windowWidth * 0.50 - choosePlayerLabel.getGlobalBounds().width * 0.5;
	float choosePlayerPosY = windowHeight * 0.10 - choosePlayerLabel.getGlobalBounds().height * 0.5;
	choosePlayerLabel.setPosition(choosePlayerPosX, choosePlayerPosY);


	std::string playerName;
	sf::Color textColor = sf::Color::Black;
	sf::Vector2f frameSize(310, 45);
	sf::Color frameColor = sf::Color::White;
	float playerNamePosX = windowWidth * 0.35;
	float playerNamePosY = windowHeight * 0.32;
	playerNameTextField = TextField(playerName, font, 35, textColor);
	playerNameTextField.setFrame(frameSize, frameColor);
	playerNameTextField.setPositon(sf::Vector2f(playerNamePosX, playerNamePosY));

	sf::String addPlayerButtonPath("image/Accept.png");
	sf::String addPlayerHoverButtonPath("image/AcceptShadow.png");
	ButtonView addPlayerButton(addPlayerButtonPath, addPlayerHoverButtonPath, false);
	float addPlayerButtonPosX = windowWidth * 0.70 - addPlayerButton.getGlobalBounds().width * 0.5;
	float addPlayerButtonPosY = windowHeight * 0.35 - addPlayerButton.getGlobalBounds().height * 0.5;
	addPlayerButton.setPosition(addPlayerButtonPosX, addPlayerButtonPosY);

	std::string playerText = "Wprowadz nazwy graczy";
	sf::Text playerLabel(playerText, font, 30);
	playerLabel.setColor(sf::Color(255, 255, 255, 255));
	float playerLabelPosX = windowWidth * 0.50 - playerLabel.getGlobalBounds().width * 0.5;
	float playerLabelPosY = windowHeight * 0.50 - playerLabel.getGlobalBounds().height * 0.5;
	playerLabel.setPosition(playerLabelPosX, playerLabelPosY);

	sf::String nextButtonPath("image/ForwardButton.png");
	ButtonView nextButton(nextButtonPath, nextButtonPath, false);
	float nextButtonPosX = windowWidth * 0.80 - nextButton.getGlobalBounds().width * 0.5;
	float nextButtonPosY = windowHeight * 0.80 - nextButton.getGlobalBounds().height * 0.5;
	nextButton.setPosition(nextButtonPosX, nextButtonPosY);

	while (running)
	{
		while (App.pollEvent(event))
		{
			sf::Mouse mouse;
			sf::Vector2i mousePos = mouse.getPosition(App);

			switch (event.type)
			{
			case  sf::Event::Closed:
				App.close();
				break;
			case sf::Event::MouseMoved:

				if (backToMenuButton.isButtonHoverd(mousePos) && mouse.isButtonPressed(sf::Mouse::Left)) { return (0); }

				if (nextButton.isButtonHoverd(mousePos) && mouse.isButtonPressed(sf::Mouse::Left)) 
				{ 
					game.setPlayersNames(players);
					return (2); 
				}

				
				if (addPlayerButton.isButtonHoverd(mousePos) && mouse.isButtonPressed(sf::Mouse::Left) && playerName.size() > 0) {
					players.push_back(playerName);
					playerName = "";
					playerNameTextField.setString(playerName);
					playerText = "";
					for (string name : players)
					{
						if (players.size() < MAX_PLAYERS || name != players.back())
							playerText += name + " vs ";
						else
							playerText += name;					
					}
					playerLabel.setString(playerText);
					playerLabelPosX = windowWidth * 0.50 - playerLabel.getGlobalBounds().width * 0.5;
					playerLabel.setPosition(playerLabelPosX, playerLabelPosY);
				}
				break;
			case sf::Event::TextEntered:
				playerName = playerNameTextField.action(event);
				break;
			default:
				break;
			}
		}

		App.clear(sf::Color(56, 134, 185, 255));	
		App.draw(playerLabel);
		App.draw(choosePlayerLabel);
		App.draw(backToMenuButton);
		playerNameTextField.draw(App);
		if (!addPlayerButton.isHidden()) App.draw(addPlayerButton);
		if (players.size() >= 2) App.draw(nextButton);
		App.display();

	}
	return (-1);
}
开发者ID:andrzej0221,项目名称:Panstwa-miasta,代码行数:101,代码来源:ChoosePlayerScreen.cpp

示例8: Render

void BackgroundObject::Render(sf::RenderWindow &window)
{

	window.draw(m_currentAnimation->getSprite());
}
开发者ID:hoshi89,项目名称:Forgotten,代码行数:5,代码来源:BackgroundObject.cpp

示例9: draw

void GameObject::draw (sf::RenderWindow &GameWindow )
{

		GameWindow.draw(GameObjectSprite);

}
开发者ID:al73rna,项目名称:BlockBreaker,代码行数:6,代码来源:GameObject.cpp

示例10: main

void main()
	{
	menu();
	while(true){
	sf::Clock clock, clockInvincible;
    score1 = 0;
	int  xBlock, yBlock, x, y, seconds = 0, red, green, blue;
	int direction = 0, directionOfBack = 0, size;
	bool checkGameOver = false, outOfBounds = false, restarter = false, breaker = false;
			size = Robjects.size();
			Robjects.erase(Robjects.begin()+0, Robjects.begin()+size);
			window.clear();
	//---------------------------------------------------------------------------
	//sf::RenderWindow window(sf::VideoMode(600, 500), "Testing");
	//---------------------------------------------------------------------------
	event.type = sf::Event::Count;
	sf::RectangleShape square(sf::Vector2f(sizex, sizey));
	square.setFillColor(sf::Color(200, 60, 0));
	square.setOutlineThickness(2);
    square.setOutlineColor(sf::Color(140, 30, 0));
	//---------------------------------------------------------------------------
	sf::RectangleShape egg(sf::Vector2f(sizex + 2, sizey + 2));
	egg.setFillColor(sf::Color(red, green, blue));
	egg.setOutlineThickness(2);
    egg.setOutlineColor(sf::Color(200, 200, 200));
	//---------------------------------------------------------------------------
	setAll(x, y, xBlock, yBlock);
	//---------------------------------------------------------------------------
  	egg.setPosition(xBlock, yBlock);
	//---------------------------------------------------------------------------
	setEgg(red, green, blue);
 while(window.isOpen())
	  {
		  if(invincible1 == true){
			  invincible2(x, y);
		for(int i = 0; i < Robjects.size(); i++){
	Robjects[i].setFillColor(sf::Color(200, 50, 50));
	Robjects[i].setOutlineThickness(2);
    Robjects[i].setOutlineColor(sf::Color(40, 40, 40));
		}
		  }
		  else 
              outOfBounds = checkOutOfBounds(x , y);

	sf::Time elapsed1 = clock.getElapsedTime();
	seconds = elapsed1.asMilliseconds();
	//---------------------------------------------------------------------------
    restarter = updateGame(x, y, xBlock, yBlock, direction, directionOfBack, checkGameOver, seconds, red, green, blue);

	egg.setFillColor(sf::Color(red, green, blue));
	if(restarter == true)
	clock.restart();
	directionOfBack = CreateTail(x, y, direction, checkGameOver, false);
   	//---------------------------------------------------------------------------
	if((x % 25 == 0)&&(y % 25 == 0)){
		//------------------------------------------------------------
		  while(window.pollEvent(event)) {
			  if(event.type == sf::Event::Closed){
			size = Robjects.size();
			Robjects.erase(Robjects.begin()+0, Robjects.begin()+size);
				  window.close();

			  }
			  //---------------------------------------------------------------------
			  if((event.key.code == sf::Keyboard::P)&&(event.type == sf::Event::KeyPressed)){
			  window.draw(square);
			  for(int i = 0; i < Robjects.size(); i++)
			  window.draw(Robjects[i]);

			  if(eggs == true){}
			  else
			  window.draw(egg);

			  window.draw(score);
		      window.display();
				  while(true){
			  while(window.pollEvent(event)) {
			  if((event.key.code == sf::Keyboard::P)&&(event.type == sf::Event::KeyPressed))
				  breaker = true;
			  			  }
			  if(breaker == true)
				  break;
			  }
			  }
				  breaker = false;
				  event.key.code == sf::Keyboard::Q;
			  if(event.type == sf::Event::KeyPressed){
			  direction = move(direction, x, y);
			  square.setPosition(x,y);
			  }
		    }
		  }
	//---------------------------------------------------------------------------
		if((checkGameOver == true)||(outOfBounds == true))
		{
			  window.clear();
		      window.draw(square);
			  for(int i = 0; i < Robjects.size(); i++)
			  window.draw(Robjects[i]);
			  window.draw(egg);
//.........这里部分代码省略.........
开发者ID:aderholdtb,项目名称:Snake-First-Ever-Project,代码行数:101,代码来源:Main.cpp

示例11: draw

void Chameleon::draw(sf::RenderWindow& window) {
    window.draw(sprite);
    if (licking) tongue.draw(window);
}
开发者ID:Pinkii-,项目名称:No-desde-el-accidente,代码行数:4,代码来源:Chameleon.cpp

示例12: addHighScores

bool addHighScores()
{
	std::ofstream outFile;
	std::ifstream inFile;
	std::string filename, name, finalName;
	std::vector<std::string> names;
	std::vector<int> scores;
	int score, count = 0, scored;
	bool enterIt = false, breaker = false;
	scored = score1;
	if(!font.loadFromFile("ethnocentric rg.ttf"))
	{
		//error...
	};

	filename = "Highscores.txt";

	inFile.open(filename);

	enterName.setString("Enter Name: ");
	enterName.setFont(font);
	enterName.setCharacterSize(20);
	enterName.setColor(sf::Color(100, 100, 100));
	enterName.setPosition(20, 357);

	nameEnter.setString(name);
	nameEnter.setFont(font);
	nameEnter.setCharacterSize(20);
	nameEnter.setColor(sf::Color(100, 100, 100));
	nameEnter.setPosition(225, 357);

	inFile>>name>>score;
	while(inFile){
      names.push_back(name);
      scores.push_back(score);
      inFile>>name>>score;
	}
//------------------------------------------------------------
if(scores.size() == 5){
for(int i = 0; i < scores.size(); i++) {
	if(scores[i] < scored)
		enterIt = true;
}
}
//------------------------------------------------------------
else {
	for(int i = 0; i < scores.size(); i++) {
	if(scores[i] < scored){
		enterIt = true;
		break;
	}
}
	if(enterIt != true) 
		enterIt = true;
}
//--------------------------------------------------------------
int i = 0;
name = "";

window.clear();
sf::Event event;

if(enterIt == true) {
	while(true){

		if(enterIt = true)
			window.clear();
		enterIt = false;
	nameEnter.setString(name);
	window.draw(enterName);
	window.draw(nameEnter);
	window.display();

	  while(window.pollEvent(event)) {
		   switch(event.type){
		   case sf::Event::TextEntered:

			   if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return)){
				   breaker = true;
				   break;
			   }
			   else if((event.text.unicode != 8)&&(i < 9)){
				   name += (char)event.text.unicode;
				   i++;
				   finalName = name;
			   }

			   else if (event.text.unicode == '\b'){
                       name = name.substr(0, name.length() - 1);
					   window.clear();
					   enterIt = true;
					   if(!i == 0)
					   i--;
                }
    }
	
	  }
	  if(breaker == true)
			   break;
	}
//.........这里部分代码省略.........
开发者ID:aderholdtb,项目名称:Snake-First-Ever-Project,代码行数:101,代码来源:Main.cpp

示例13: highScores

void highScores()
{
	bool exit1 = false;
	std::string filename, name1, score1;
	std::vector<sf::Text> HighNames;
	std::vector<sf::Text> HighScores;
	int x = 75, y = 100, x2 = 300, y2 = 100, size;
	filename = "Highscores.txt";
    std::ifstream inFile(filename);

	if(!font.loadFromFile("ethnocentric rg.ttf"))
	{
		//error...
	};

	int count = 0;
	inFile>>name1>>score1;

	while(count != 5){
	HighName.setString(convertInt(count + 1) + ".  " + name1);
	HighName.setFont(font);
	HighName.setCharacterSize(20); 
	HighName.setColor(sf::Color(50, 50, 50));
	HighName.setPosition(x, y + (50 * count));

	HighScore.setString(score1);
	HighScore.setFont(font);
	HighScore.setCharacterSize(20);
	HighScore.setColor(sf::Color(50, 50, 50));
	HighScore.setPosition(x2, y2 + (50 * count));

	HighScoreTitle.setString("High Scores");
	HighScoreTitle.setFont(font);
	HighScoreTitle.setCharacterSize(50);
	HighScoreTitle.setColor(sf::Color(130, 30, 30));
	HighScoreTitle.setPosition(50, 20);

	menuButton.setString("Menu");
	menuButton.setFont(font);
	menuButton.setCharacterSize(20);
	menuButton.setColor(sf::Color(100, 100, 100));
	menuButton.setPosition(100, 357);

	sf::RectangleShape menu(sf::Vector2f(80, 40));
	menu.setFillColor(sf::Color(255, 0, 0));
	menu.setOutlineThickness(4);
    menu.setOutlineColor(sf::Color(255, 100, 0));
	menu.setPosition(100, 350);

		HighNames.push_back(HighName);
		HighScores.push_back(HighScore);
		count++;
		name1 = "";
		score1 = "";
		inFile>>name1>>score1;
	}
	
	size = HighNames.size();

window.clear();
window.draw(HighScoreTitle);
window.draw(HighNames[0]);
window.draw(HighScores[0]);
window.draw(HighNames[1]);
window.draw(HighScores[1]);
window.draw(HighNames[2]);
window.draw(HighScores[2]);
window.draw(HighNames[3]);
window.draw(HighScores[3]);
window.draw(HighNames[4]);
window.draw(HighScores[4]);
window.draw(menuButton);
window.display();
while(true){
		  while(window.pollEvent(event)) {
			  			  if(event.type == sf::Event::Closed){
			size = Robjects.size();
			Robjects.erase(Robjects.begin()+0, Robjects.begin()+size);
				  window.close();

			  }
			 if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
				 sf::Vector2i localPosition = sf::Mouse::getPosition(window);
				 x = localPosition.x;
				 y = localPosition.y;
				 if((x > 100) && (x < 180) && (y < 390) && (y > 350))
					exit1 = true;
			 }
		  }
			 if(exit1 == true)
				 break;
	}
inFile.close();
window.clear();
}
开发者ID:aderholdtb,项目名称:Snake-First-Ever-Project,代码行数:95,代码来源:Main.cpp

示例14: exit

bool exit()
{
	int x, y, size;
	bool exit1 = false;

	if(addHighScores() == true)
		return true;

	if(!font.loadFromFile("ethnocentric rg.ttf"))
	{
		//error...
	};
	gameOver.setString("Game Over");
	gameOver.setFont(font);
	gameOver.setCharacterSize(50);
	gameOver.setColor(sf::Color(200, 200, 0));
	gameOver.setPosition(85, 200);

	sf::RectangleShape exit2(sf::Vector2f(80, 40));
	exit2.setFillColor(sf::Color(255, 0, 0));
	exit2.setOutlineThickness(4);
    exit2.setOutlineColor(sf::Color(255, 100, 0));
	exit2.setPosition(250, 350);

	sf::RectangleShape menu(sf::Vector2f(80, 40));
	menu.setFillColor(sf::Color(255, 0, 0));
	menu.setOutlineThickness(4);
    menu.setOutlineColor(sf::Color(255, 100, 0));
	menu.setPosition(100, 350);

	exitButton.setString("Exit");
	exitButton.setFont(font);
	exitButton.setCharacterSize(20);
	exitButton.setColor(sf::Color(30, 30, 30));
	exitButton.setPosition(260, 357);

	menuButton.setString("Menu");
	menuButton.setFont(font);
	menuButton.setCharacterSize(20);
	menuButton.setColor(sf::Color(30, 30, 30));
	menuButton.setPosition(100, 357);
	        window.draw(gameOver);
			  window.draw(exit2);
			  window.draw(menu);
			  window.draw(gameOver);
			  window.draw(exitButton);
			  window.draw(menuButton);
		      window.display();
	while(true){
		  while(window.pollEvent(event)) {
			  if(event.type == sf::Event::Closed)
				  window.close();

			 if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
				 sf::Vector2i localPosition = sf::Mouse::getPosition(window);
				 x = localPosition.x;
				 y = localPosition.y;
				 if((x > 100) && (x < 180) && (y < 390) && (y > 350)){
					exit1 = true;
				 }
				 else if((x > 250) && (x < 330) && (y < 390) && (y > 350)){
			size = Robjects.size();
			Robjects.erase(Robjects.begin()+0, Robjects.begin()+size);
				 window.close();
				 }
		       }
	         }

			  if(exit1 == true)
				  break;

			  size = Robjects.size();
			Robjects.erase(Robjects.begin()+0, Robjects.begin()+size);
	}
	window.clear();
	return true;
}
开发者ID:aderholdtb,项目名称:Snake-First-Ever-Project,代码行数:77,代码来源:Main.cpp

示例15: run

int WaitingMenu::run(sf::RenderWindow &window, CommonData* commonData) {
    // Create background
    sf::Sprite background(commonData->defaultBackgroundTexture);

    // Create menu title
    Label* lobbyTitle = new Label("Lobby", 100, commonData);
    lobbyTitle->setPosition((SCREEN_WIDTH - lobbyTitle->getWidth()) / 2, 50);

    // Teams labels
    Label* blueTeamLabel = new Label("Blue team", 70, 150, 200, commonData);
    blueTeamLabel->setColor(sf::Color::Blue);
    Label* redTeamLabel = new Label("Red team", 70, commonData);
    redTeamLabel->setPosition(SCREEN_WIDTH - redTeamLabel->getWidth() - 150, 200);
    redTeamLabel->setColor(sf::Color::Red);

    // Players labels
    Label** playerLabel = new Label*[4];
    for (int i = 0; i < 4; i++) {
        playerLabel[i] = new Label("", 60, 180, 300 + (i/2)*100, commonData);
        if (i % 2 == 1) {
            playerLabel[i]->setPosition(SCREEN_WIDTH - playerLabel[i]->getWidth() - 180, 300 + (i/2)*100);
        }
    }

    // Countdown label
    Label* countdownLabel = new Label("The game will start in 15 seconds...", 40, commonData);
    countdownLabel->setPosition(SCREEN_WIDTH - countdownLabel->getWidth() - 30, 600);

    // Countdown
    sf::Clock clock;
    sf::Time fiveteenSeconds = sf::seconds(15.0f);
    int amountOfPlayers = 0;

    // Main loop
    while (window.isOpen()) {
        // Position of mouse
        sf::Vector2i position = sf::Mouse::getPosition(window);

        // Process events
        sf::Event event;
        while (window.pollEvent(event)) {
            // Close window: exit
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            // Escape pressed: exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }
        }

        // Show players name on labels
        for (int i = 0; i < commonData->map->playersSize(); i++) {
            Player* player = commonData->map->getPlayerAtIndex(i);
            playerLabel[player->getID()]->setString(player->getName());
        }

        // Prepare countdown information
        if ((amountOfPlayers != commonData->map->playersSize()) && (commonData->map->playersSize() == 2 || commonData->map->playersSize() == 4)) {
            clock.restart();
            amountOfPlayers = commonData->map->playersSize();
        }

        // Clear screen
        window.clear(sf::Color::Black);

        // Draw
        window.draw(background);
        lobbyTitle->draw(window);
        blueTeamLabel->draw(window);
        redTeamLabel->draw(window);
        for (int i = 0; i < 4; i++) {
            if (i % 2 == 1) {
                playerLabel[i]->setPosition(SCREEN_WIDTH - playerLabel[i]->getWidth() - 180, 300 + (i/2)*100);
            }
            playerLabel[i]->draw(window);
        }

        // Show information about starting game only when there are 2 or 4 players
        if (commonData->map->playersSize() == 2 || commonData->map->playersSize() == 4) {
            int timeToStart = (int)ceil(fiveteenSeconds.asSeconds() - clock.getElapsedTime().asSeconds());
            if (timeToStart <= 3) {
                timeToStart = 3;
            }
            countdownLabel->setString("The game will start in " + Converter::int2string(timeToStart) + " seconds...");
            countdownLabel->setPosition(SCREEN_WIDTH - countdownLabel->getWidth() - 30, 600);
            countdownLabel->draw(window);
        }

        // Update the window
        window.display();

        // Go to the game if countdown will finish
        if ((amountOfPlayers == 2 || amountOfPlayers == 4) && clock.getElapsedTime().asSeconds() > fiveteenSeconds.asSeconds() - 3.0f && commonData->gameStarted == true) {
            return GAME;
        }
    }

    // Change screen
//.........这里部分代码省略.........
开发者ID:jpowie01,项目名称:Bulletline,代码行数:101,代码来源:WaitingMenu.cpp


注:本文中的sf::RenderWindow::draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。