本文整理汇总了C++中sf::Text::setFont方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::setFont方法的具体用法?C++ Text::setFont怎么用?C++ Text::setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::setFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
void initialize(sf::RenderWindow &mainWindow, sf::Font &mainFont)
{
titleText.setFont(mainFont);
titleText.setString("Triangle Super");
titleText.setCharacterSize(72);
titleText.setPosition(mainWindow.getSize().x/2 - titleText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/2 - titleText.getGlobalBounds().height/2.f);
playText.setFont(mainFont);
playText.setString("Play!");
playText.setCharacterSize(30);
playText.setPosition(mainWindow.getSize().x/3 - playText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/3 *2 - playText.getGlobalBounds().height/2.f);
quitText.setFont(mainFont);
quitText.setString("Quit.");
quitText.setCharacterSize(30);
quitText.setPosition(mainWindow.getSize().x/3 *2 - quitText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/3*2-quitText.getGlobalBounds().height/2.f);
scoreText.setFont(mainFont);
scoreText.setCharacterSize(30);
scoreText.setPosition(mainWindow.getSize().x/2 - scoreText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/3-scoreText.getGlobalBounds().height/2.f);
}
示例2: init
void init() {
this->restart();
// RectangleShapes
sf::Vector2f unit(unit_w, unit_h);
stone_view = sf::RectangleShape(unit);
stone_view.setFillColor(sf::Color(255, 81, 68));
body_view = sf::RectangleShape(unit);
body_view.setFillColor(sf::Color(0, 204, 255));
food_view = sf::RectangleShape(unit);
food_view.setFillColor(sf::Color(19, 169, 136));
// font & msg
if (!font.loadFromFile("Inconsolata-Bold.ttf")) {
puts("fonts loading error!");
this->close();
}
msg1.setFont(font);
msg1.setColor(sf::Color::White);
msg1.setCharacterSize(50);
msg1.setPosition(80, 100);
msg2.setFont(font);
msg2.setColor(sf::Color::White);
msg2.setCharacterSize(25);
msg2.setString("Press <Enter> to Replay");
msg2.setPosition(60, 250);
}
示例3: gameWindow
Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
{
ball.setFillColor(sf::Color::Cyan);
ball.setPosition(100.0, 100.0);
ball.setRadius(10.f);
p1Paddle.setFillColor(sf::Color::Green);
p1Paddle.setPosition(10.0, 100.0);
p1Paddle.setSize(sf::Vector2f(10.0, 100.0));
p2Paddle.setFillColor(sf::Color::Red);
p2Paddle.setPosition(580.0, 100.0);
p2Paddle.setSize(sf::Vector2f(10.0, 100.0));
p1MovingUp = false;
p1MovingDown = false;
p2MovingUp = false;
p2MovingDown = false;
ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
font.loadFromFile("arial.ttf");
p1ScoreText.setPosition(150, 10);
p1ScoreText.setFont(font);
p1ScoreText.setString(std::to_string(p1Score));
p1ScoreText.setColor(sf::Color::Red);
p1ScoreText.setCharacterSize(24);
p2ScoreText.setPosition(450, 10);
p2ScoreText.setFont(font);
p2ScoreText.setString(std::to_string(p2Score));
p2ScoreText.setColor(sf::Color::Red);
p2ScoreText.setCharacterSize(24);
}
示例4: init
void WindowCreateThing::init(sf::RenderWindow &window) {
rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
rectTitle.setFillColor(sf::Color(158, 158, 158));
rectTitle.setOutlineColor(sf::Color::Black);
rectTitle.setOutlineThickness(1.f);
rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
rectMain.setFillColor(sf::Color::White);
rectMain.setOutlineColor(sf::Color::Black);
rectMain.setOutlineThickness(1.f);
load();
starting_position = sf::Mouse::getPosition(window);
textTitle.setFont(font);
textTitle.setString("CreateThings.txt");
textTitle.setCharacterSize(24);
textTitle.setColor(sf::Color::White);
textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
//textTitle.setPosition(sf::Vector2f(400,10));
textClose.setFont(font);
textClose.setString("X");
textClose.setStyle(sf::Text::Bold);
textClose.setCharacterSize(35);
textClose.setColor(sf::Color::White);
textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));
///// FOLDER ICONE
textureFolder.setSmooth(true);
spriteFodler.setTexture(textureFolder);
sf::Vector2f targetSize(25.0f, 25.0f);
spriteFodler.setScale(
targetSize.x / spriteFodler.getLocalBounds().width,
targetSize.y / spriteFodler.getLocalBounds().height);
spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));
///// CLOSE ICONE
/*textureClose.setSmooth(true);
spriteClose.setTexture(textureClose);
sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
spriteClose.setScale(
targetSize2.x / spriteClose.getLocalBounds().width,
targetSize2.y / spriteClose.getLocalBounds().height);
spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
示例5: 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();
};
示例6: initTexts
void initTexts()
{
if (!font.loadFromFile("arial.ttf"))cout << "error";
endText.setFont(font);
endText.setString("Game Over");
endText.setCharacterSize(50);
endText.setColor(sf::Color( 156, 39, 176));
endText.setPosition(SIZE/2-100,SIZE/2-100);
scoreText.setFont(font);
scoreText.setCharacterSize(50);
scoreText.setColor(sf::Color(255,255,255));
scoreText.setPosition(SIZE/2-200,SIZE/2);
}
示例7: 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();
};
示例8: initializeText
//private function to initialize the text easier
//precondition: the Font must have opened correctly
void RoundEndScreen::initializeText(sf::Font &font, sf::Text &text, float x_position, float y_position, int size)
{
text.setFont(font);
text.setCharacterSize(size);
text.setPosition(x_position, y_position);
text.setColor(sf::Color::White);
}
示例9: Initialize
void Scoring::Initialize()
{
font.loadFromFile("./Resources/Fonts/jokerman.ttf");
points_graphics.setFont(font);
points_graphics.setCharacterSize(24);
points_graphics.setString("0");
}
示例10: 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]);
}
}
示例11:
//Player constructor.
Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) {
mSprite.setTexture(texture);
mRect = sf::FloatRect(x, y, 120, 110); //Character x, y, width, height.
mName = "Player 1";
mTextName.setString(mName);
mTextName.setFont(font);
mTextName.setCharacterSize(30);
mTextName.setStyle(sf::Text::Bold);
mTextName.setColor(sf::Color::Red);
mHpSprite.setTexture(hpImage);
mHpSprite.setTextureRect(sf::IntRect(0, 0, 100, 10));
mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
mSpeed = 0.1;
mMovement.x = 0;
mMovement.y = 0;
mCurrentFrame = 0;
mAnimationSpeed = 0.005;
mIsAlive = true;
mHP = 100;
mMaxHp = 100;
mMP = 100;
}
示例12: prepareText
void Game::prepareText(sf::Text &text, int height)
{
text.setFont(font);
text.setCharacterSize(Game::characterSize);
text.setStyle(sf::Text::Bold);
text.setColor(sf::Color::White);
text.setPosition(420, height);
}
示例13: getText
void getText(sf::Text & txt, sf::Font & font,char* str, int x, int y, int size)
{
txt.setFont(font);
txt.setString(str);
txt.setColor(sf::Color::Black);
txt.setPosition(x,y);
txt.setCharacterSize(size);
}
示例14: draw
/**
Text drawing for buttons.
*/
void SpriteManager::draw (sf::Text button_text, int x, int y, int width, int height, sf::RenderWindow &window) {
button_text.setFont (font);
sf::FloatRect text_rect = button_text.getLocalBounds ();
button_text.setPosition ((x + (width / 2)) - (button_text.getLocalBounds ().width / 2), (y + (height / 2)) - (button_text.getLocalBounds ().height));//Centers text to button.
window.draw (button_text);
}
示例15: 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));
}