C++ C++;菜单sfml中心所有内容
主菜单:C++ C++;菜单sfml中心所有内容,c++,menu,window,center,sfml,C++,Menu,Window,Center,Sfml,主菜单: enter code sf::FloatRect textRect = text.getLocalBounds(); //Font if(!font.loadFromFile("arial.ttf")){} //Tło - trzeba załadować if(!texture.loadFromFile("bg_menu.png")){} //play mainMenu[0].setFont(font); mainMenu[0].setFillColor(sf::Color::B
enter code sf::FloatRect textRect = text.getLocalBounds();
//Font
if(!font.loadFromFile("arial.ttf")){}
//Tło - trzeba załadować
if(!texture.loadFromFile("bg_menu.png")){}
//play
mainMenu[0].setFont(font);
mainMenu[0].setFillColor(sf::Color::Blue);
mainMenu[0].setString("Play");
mainMenu[0].setCharacterSize(40);
mainMenu[0].setPosition(sf::Vector2f(width / 2, hight / (Max_main_menu + 1)));
//center text (?)
mainMenu[0].setOrigin(textRect.left + textRect.width / 2.0f,
textRect.top + textRect.height / 2.0f);
mainMenu[1].setOrigin(textRect.left + textRect.width / 2.0f,
textRect.top + textRect.height / 2.0f);
mainMenu[2].setOrigin(textRect.left + textRect.width / 2.0f,
textRect.top + textRect.height / 2.0f);
enter main(){
RenderWindow窗口(视频模式(屏幕高,屏幕宽),“蚂蚁时代!”,样式::关闭);
主菜单(屏幕宽度、屏幕高度);
while(window.isOpen()){
sf::事件;
while(window.pollEvent(事件)){
如果(event.type==sf::event::Closed)
window.close();
//在菜单中移动-上下并选择开始
if(event.type==event::keyreased){
if(event.key.code==键盘::向上){
menu.moveUP();
打破
}
if(event.key.code==键盘::向下){
menu.moveDOWN();
打破
}
if(event.key.code==键盘::返回){
开关(menu.mainMenuPressed()){
案例0:
cout如果要将任何图像或文本居中,则
enter main(){
RenderWindow window(VideoMode(SCREEN_HIGH, SCREEN_WIDTH), "Age of Ants!", Style::Close);
Main_menu menu(SCREEN_WIDTH, SCREEN_HIGH);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
//Movin in Menu - Up&Down&Selecting start
if (event.type == Event::KeyReleased) {
if (event.key.code == Keyboard::Up) {
menu.moveUP();
break;
}
if (event.key.code == Keyboard::Down) {
menu.moveDOWN();
break;
}
if (event.key.code == Keyboard::Return) {
switch (menu.mainMenuPressed()) {
case 0:
cout << "Play button has been pressed" << endl;
break;
case 1:
cout << "Options button has been pressed" << endl;
break;
case 2:
window.close();
cout << "Exit button has been pressed" << endl;
break;
这适用于原点位于图像左上角的图像
sf::Vector2f position;
position.x = ((windowSize.x - imageSize.x) / 2.0f);
position.y = ((windowSize.y - imageSize.y) / 2.0f);