本文整理汇总了C++中sf::Text::setOrigin方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::setOrigin方法的具体用法?C++ Text::setOrigin怎么用?C++ Text::setOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::setOrigin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
virtual void init()
{
dt=0;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
darken = sf::RectangleShape(sf::Vector2f(800,400));
tit.setFont(standard_font);
score.setFont(standard_font);
std::stringstream ss;
ss << your_score;
std::string str = ss.str();
tit.setString("Congrats! You beat the game\nIt took you:");
score.setString(str + " seconds");
tit.setCharacterSize(24);
score.setCharacterSize(24);
// dla centrowania obiektow
sf::FloatRect tempt = tit.getGlobalBounds();
sf::FloatRect tempr = score.getGlobalBounds();
tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
score.setOrigin(sf::Vector2f(tempr.width/2,tempr.height/2));
tit.setPosition(400,150);
score.setPosition(400,200);
score.setColor(sf::Color(0,127,127));
timer.restart();
};
示例2: showMission
void showMission(Game1 & game, MissionText & mission_text, sf::Text & text, Hero & hero, MenuImg & fon, menuBools & bools)
{
if (!bools.first_play) {
switch (hero.player->quest)
{
case Player::quest_status::start: text.setString(mission_text.start); break;
case Player::quest_status::find_car: text.setString(mission_text.find_car); break;
case Player::quest_status::find_gaz: text.setString(mission_text.find_gaz); break;
case Player::quest_status::find_busket: text.setString(mission_text.find_buscket); break;
case Player::quest_status::find_colon: text.setString(mission_text.find_colon); break;
case Player::quest_status::go_to_car: text.setString(mission_text.go_to_car); break;
}
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x + 220, fon.sprite->getPosition().y - 250);
text.setColor(Color::Red);
game.window->draw(text);
}
else {
fon.hand_sprite->setPosition(fon.sprite->getPosition().x + 200, fon.sprite->getPosition().y);
game.window->draw(*fon.hand_sprite);
}
game.aim_sprite->setPosition(game.pos);
game.window->draw(*game.aim_sprite);
game.window->display();
}
示例3: pauseMenu
void pauseMenu()
{
pause.setFont(myFont);
pause.setCharacterSize(WIDTH / 16);
pause.setStyle(sf::Text::Bold);
pause.setColor(sf::Color::Black);
pause.setString("PAUSE");
pause.setOrigin(pause.getLocalBounds().width / 2, pause.getLocalBounds().height / 2);
pause.setPosition(WIDTH / 2, 3 * HEIGHT / 16);
sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);
for (int i = 0; i < pauseMenuRect.size(); i++)
{
pauseMenuRect[i].setSize(menuRectSize);
pauseMenuRect[i].setFillColor(grey);
pauseMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
pauseMenuRect[i].setPosition(WIDTH / 2, 6 * HEIGHT / 16 + i * (5 * HEIGHT / 32));
pauseMenuText[i].setFont(myFont);
pauseMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
pauseMenuText[i].setStyle(sf::Text::Bold);
pauseMenuText[i].setColor(sf::Color::Black);
pauseMenuText[i].setString(pauseMenuCommands[i]);
pauseMenuText[i].setOrigin(pauseMenuText[i].getLocalBounds().width / 2, pauseMenuText[i].getLocalBounds().height / 2);
pauseMenuText[i].setPosition(pauseMenuRect[i].getPosition().x, pauseMenuRect[i].getPosition().y);
}
BILLIARDS.draw(pause);
for (int i = 0; i < pauseMenuRect.size(); i++)
{
BILLIARDS.draw(pauseMenuRect[i]);
BILLIARDS.draw(pauseMenuText[i]);
}
}
示例4: origin_from_text
void origin_from_text(sf::Text text)
{
const sf::FloatRect rectangle{text.getLocalBounds()};
text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
}
示例5: set_origin
void set_origin()
{
const sf::FloatRect rectangle{m_text.getLocalBounds()};
m_text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
}
示例6: createOption
void MenuState::createOption(sf::Text& textOption, int order, std::string s){
textOption.setFont(terminal); //This font is blurry need another one!
textOption.setCharacterSize(20);
textOption.setString(s);
textOption.setOrigin(static_cast<int> (textOption.getLocalBounds().width / 2), static_cast<int>(textOption.getLocalBounds().height / 2));
textOption.setPosition(static_cast<int>((window.getDefaultView().getSize().x) / 2), 130 + order*50);
textOption.setColor(sf::Color(128,128,128));
}
示例7: MoveDraw
void MoveDraw()
{
moves.setFont(myFont);
moves.setCharacterSize(12);
moves.setStyle(sf::Text::Bold);
moves.setColor(sf::Color::Red);
moves.setOrigin(moves.getLocalBounds().width / 2, moves.getLocalBounds().height / 2);
moves.setPosition(WIDTH * 3 / 4, borderDepth / 2);
bestScore.setFont(myFont);
bestScore.setCharacterSize(12);
bestScore.setStyle(sf::Text::Bold);
bestScore.setColor(sf::Color::Red);
bestScore.setOrigin(bestScore.getLocalBounds().width / 2, bestScore.getLocalBounds().height / 2);
bestScore.setPosition(WIDTH * 1 / 4, borderDepth / 2);
stringstream mess2;
if (BS != 0)
mess2 << "Best Score: " << BS;
else
mess2 << "Best Score: --";
string message2 = mess2.str();
bestScore.setString(message2);
if ((twoPlayerGame) || (pause2P))
{
if (mover > 2)
mover = 1;
stringstream mess;
mess << "Player " << mover << "'s turn";
string message = mess.str();
moves.setString(message);
BILLIARDS.draw(moves);
}
else
{
stringstream mess;
mess << "Moves: " << mover;
string message = mess.str();
moves.setString(message);
BILLIARDS.draw(bestScore);
if ((onePlayerGame)||(pause1P))
BILLIARDS.draw(moves);
}
}
示例8: UpdateText
//will update the string of the text if needed and color and will keep the text centered if specified
void FontManager::UpdateText(sf::Text& text, const char* txt, sf::Color color, bool setOrigin)
{
if (txt != NULL)
text.setString(txt);
if (setOrigin)
text.setOrigin(text.getGlobalBounds().width / 2.0f, text.getLocalBounds().height / 2.0f);
text.setColor(color);
}
示例9: generateGameModeButton
void MenuScreen::generateGameModeButton(sf::Text& button, const string& modeName,
short position, const sf::Font *font,
const sf::Vector2u& screenSize )
{
button = sf::Text( modeName, *font );
button.setColor( sf::Color::Blue );
button.setStyle( sf::Text::Regular );
sf::FloatRect textRect = button.getGlobalBounds();
button.setOrigin( textRect.left + textRect.width / 2.0f,
textRect.top + textRect.height / 2.0f );
button.setPosition( screenSize.x / 2, screenSize.y * 0.2 + position * Constants::LENGTH_BUTTON_SEPERATION );
}
示例10: drawNumbers
void drawNumbers(sf::RenderWindow & window,sf::Text & text, float bgHeight) {
std::string textNum;
sf::Vector2f position = getCenter(window);
for (int i = 0; i < NUMBER_OF_DIGITS; i++) {
position = polarToCartesianSys(bgHeight * 0.5f - text.getGlobalBounds().height * 2, 30.f * ( i + 1 ) - 90);
text.setString(std::to_string( i + 1 ));
text.setOrigin(text.getGlobalBounds().width * 0.5f, text.getGlobalBounds().height * 0.5f);
text.setPosition(position.x + window.getSize().x * 0.5f, position.y + window.getSize().y * 0.5f);
window.draw(text);
}
}
示例11: init
virtual void init()
{
dt=0;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
darken = sf::RectangleShape(sf::Vector2f(800,400));
tit.setFont(standard_font);
tit.setString("Made by");
explain.setFont(standard_font);
explain.setString("Just a bored slacker");
explain.setCharacterSize(36);
explain.setPosition(260,320);
tit.setCharacterSize(24);
// dla centrowania obiektow
sf::FloatRect tempt = tit.getGlobalBounds();
tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
tit.setPosition(400,120);
if (!tex.loadFromFile("gfx/jabslogo.png"))
{
std::cout<<"Fuckup"<<std::endl;
}
spr.setTexture(tex);
spr.setPosition(334,144);
timer.restart();
};
示例12: init
virtual void init()
{
dt=0;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
darken = sf::RectangleShape(sf::Vector2f(800,400));
tit.setFont(standard_font);
subtit.setFont(standard_font);
tit.setString(title);
subtit.setString(subtitle);
tit.setCharacterSize(24);
subtit.setCharacterSize(18);
// dla centrowania obiektow
sf::FloatRect tempt = tit.getGlobalBounds();
sf::FloatRect temps = subtit.getGlobalBounds();
tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
subtit.setOrigin(sf::Vector2f(temps.width/2,temps.height/2));
tit.setPosition(400,150);
subtit.setPosition(400,180);
timer.restart();
};
示例13: endGame
void endGame()
{
endTitle.setFont(myFont);
endTitle.setCharacterSize(WIDTH / 16);
endTitle.setStyle(sf::Text::Bold);
endTitle.setColor(sf::Color::Black);
string str;
if (end1P)
{
stringstream message;
message << "Final score: " << mover;
str = message.str();
}
else if (end2P)
{
stringstream message;
message << "Player " << mover << " wins!";
str = message.str();
}
endTitle.setString(str);
endTitle.setOrigin(endTitle.getLocalBounds().width / 2, endTitle.getLocalBounds().height / 2);
endTitle.setPosition(WIDTH / 2, 2 * HEIGHT / 5);
sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);
for (int i = 0; i < endMenuRect.size(); i++)
{
endMenuRect[i].setSize(menuRectSize);
endMenuRect[i].setFillColor(grey);
endMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
endMenuRect[i].setPosition(WIDTH / 2, 4 * HEIGHT / 5);
endMenuText[i].setFont(myFont);
endMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
endMenuText[i].setStyle(sf::Text::Bold);
endMenuText[i].setColor(sf::Color::Black);
endMenuText[i].setString(endMenuCommands[i]);
endMenuText[i].setOrigin(endMenuText[i].getLocalBounds().width / 2, endMenuText[i].getLocalBounds().height / 2);
endMenuText[i].setPosition(endMenuRect[i].getPosition().x, endMenuRect[i].getPosition().y);
}
BILLIARDS.draw(endTitle);
for (int i = 0; i < endMenuRect.size(); i++)
{
BILLIARDS.draw(endMenuRect[i]);
BILLIARDS.draw(endMenuText[i]);
}
}
示例14: showMenu
void showMenu(Game1 & game, MenuText & menu_text, sf::Text & text, MenuImg & fon, menuBools & bools)
{
game.window->draw(*fon.sprite);
if (!bools.about) {
text.setString(menu_text.new_game);
menu_text.new_game_rect = { fon.sprite->getPosition().x - menu_text.new_game_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.new_game_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
_choose_color(text, game.pos, menu_text.new_game_rect);
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x - menu_text.new_game_pos.x, fon.sprite->getPosition().y - menu_text.new_game_pos.y);
game.window->draw(text);
text.setString(menu_text.continue_game);
menu_text.continue_game_rect = { fon.sprite->getPosition().x - menu_text.continue_game_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.continue_game_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
if (bools.first_play) {
text.setColor(Color(128, 128, 128));
}
else {
_choose_color(text, game.pos, menu_text.continue_game_rect);
}
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x - menu_text.continue_game_pos.x, fon.sprite->getPosition().y - menu_text.continue_game_pos.y);
game.window->draw(text);
text.setString(menu_text.about);
menu_text.about_rect = { fon.sprite->getPosition().x - menu_text.about_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.about_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
_choose_color(text, game.pos, menu_text.about_rect);
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x - menu_text.about_pos.x, fon.sprite->getPosition().y - menu_text.about_pos.y);
game.window->draw(text);
text.setString(menu_text.exit);
menu_text.exit_rect = { fon.sprite->getPosition().x - menu_text.exit_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.exit_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
_choose_color(text, game.pos, menu_text.exit_rect);
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x - menu_text.exit_pos.x, fon.sprite->getPosition().y - menu_text.exit_pos.y);
game.window->draw(text);
}
else {
text.setColor(Color::Red);
text.setString(menu_text.about_text);
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x - menu_text.about_text_pos.x, fon.sprite->getPosition().y - menu_text.about_text_pos.y);
game.window->draw(text);
text.setString(menu_text.back);
menu_text.back_rect = { fon.sprite->getPosition().x - menu_text.back_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.back_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
_choose_color(text, game.pos, menu_text.back_rect);
text.setOrigin(text.getLocalBounds().width / 2, 0);
text.setPosition(fon.sprite->getPosition().x - menu_text.back_pos.x, fon.sprite->getPosition().y - menu_text.back_pos.y);
game.window->draw(text);
}
}
示例15: CenterTextVert
void CenterTextVert(sf::Text& message, const sf::RenderTarget& target)
{
sf::FloatRect message_bounds = message.getLocalBounds();
message.setOrigin(0, message_bounds.top + (message_bounds.height/2.f));
message.setPosition(message.getPosition().x, target.getSize().y/2.f);
}