本文整理汇总了C++中sf::Text类的典型用法代码示例。如果您正苦于以下问题:C++ Text类的具体用法?C++ Text怎么用?C++ Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: arrange
void DropDown::arrange(sf::Text &text,sf::RectangleShape &shape)
{
float ratiox = shape.getGlobalBounds().width/text.getGlobalBounds().width;
float ratioy = (shape.getGlobalBounds().height/text.getGlobalBounds().height);
ratioy*=0.5f;
text.scale(ratiox,ratioy);
}
示例2: addMessage
void LogMessageWindow::addMessage(sf::Text msg){
if (msg_queue.empty()){
std::cout << "Msg queue is empty\n";
//reposition the text to the boundaries of the message log window
msg.setPosition(sf::Vector2f(this->message_window_background.getPosition().x + 10,
this->message_window_background.getPosition().y +
message_window_background.getSize().y - 14 ));
}
//When the number of messages in the queue reach the height of the message window, clear it.
else if ( ((int)message_window_background.getSize().y / 14) == msg_queue.size()){//Division by constant, constant is the position of each message
msg_queue.clear();
msg.setPosition(sf::Vector2f(this->message_window_background.getPosition().x + 10,
this->message_window_background.getPosition().y +
message_window_background.getSize().y - 14));
}
else{
std::cout << "Msg queue is NOT empty\n";
msg.setPosition(sf::Vector2f(message_window_background.getPosition().x + 10, msg_queue.back().getPosition().y - 14.0f));
}
msg_queue.push_back(msg);
}
示例3: getCenter
sf::Vector2f getCenter(const sf::Text& text)
{
sf::Vector2f center = text.getPosition();
center.x += text.getLocalBounds().width / 2.f;
center.y += text.getLocalBounds().height / 2.f;
return center;
}
示例4: Draw
void Item::Draw(sf::RenderWindow& renderWindow, sf::Text &text)
{
TextureManager *t = Resources::getTextureManager("tileMap");
sf::Sprite s;
sf::Vector2f item_pos = GetPosition();
t->generateSprite(id, item_pos, s, sf::Vector2f(GetWidth(),GetHeight()));
renderWindow.draw(s);
sf::Vector2f test_pos = GetPosition();
text.setPosition(test_pos.x, test_pos.y);
text.setScale(sf::Vector2f(1.5,1.5));
renderWindow.draw(text);
//renderWindow.draw(_sprite);
/*if(amount >0){
char c[10];
sprintf(c, "%i", amount);
std::string string(c);
sf::String str(string);
text.setString(str);
text.setPosition(GetPosition().x, GetPosition().y);
renderWindow.draw(text);
}*/
}
示例5: update
//Enemy sprite render.
void update(float deltaTime, char** levelMap, struct config* config) {
if(mDirection == 0) {mMovement.x = 0; mMovement.y = -mSpeed;}
if(mDirection == 1) {mMovement.x = mSpeed; mMovement.y = 0;}
if(mDirection == 2) {mMovement.x = 0; mMovement.y = mSpeed;}
if(mDirection == 3) {mMovement.x = mSpeed; mMovement.y = 0;}
mRect.left += mMovement.x * deltaTime;
collision(levelMap, config);
mRect.top += mMovement.y * deltaTime;
collision(levelMap, config);
//Enemy animation.
mCurrentFrame += mAnimationSpeed * deltaTime;
if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount;
if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height));
if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height));
if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height));
if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height));
mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);
mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY);
}
示例6: 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]);
}
}
示例7: onEvent
void CustomMenu::onEvent(const sf::Event& event) {
Component* triggered = nullptr;
while((triggered = popEvent(event))) {
math::u_id id = triggered->getID();
if(id == save->getID()) {
} else if(id == load->getID()) {
} else if(id == random->getID()) {
conv << (Utility::Random::getUnsignedRandom()%1001);
name_f->setText(SentenceGenerator::getWord(SentenceGenerator::Noun) +
SentenceGenerator::getWord(SentenceGenerator::Noun));
age_f->setText(conv.str());
gender->randomize();
//palette->randomize();
conv.str("");
} else if(id == back->getID())
MenuUtils::mainMenu();
else if(id == name_f->getID())
name.setColor(name_f->getColor());
else if(id == age_f->getID())
age.setColor(age_f->getColor());
else
std::cerr << "Auto-destruction sequence activated. Nooooo!!!" << std::endl;
}
}
示例8:
void Cursor::setCursorPos(const sf::Text &text)
{
sf::FloatRect textSize = text.getGlobalBounds();
sf::Vector2f textPos = text.getPosition();
_cursor.setPosition(textSize.width + textPos.x, textPos.y);
}
示例9: Player
//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;
}
示例10: 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);
}
示例11: 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);
}
示例12: breakTextLines
void breakTextLines(sf::Text& t, float maxX)
{
sf::String s = t.getString();
std::size_t lastBreakCharIdx = s.getSize();
static sf::String const breakBeforeChars("([{\"'`'");
static auto const isBreakBeforeChar = [] (sf::Uint32 c) {
return breakBeforeChars.find(c) != sf::String::InvalidPos;
};
for (std::size_t i = 0; i < s.getSize(); ++i) {
if (t.findCharacterPos(i).x > maxX) {
if (lastBreakCharIdx > i)
lastBreakCharIdx = i;
if (s.getSize() > lastBreakCharIdx &&
!std::iswgraph(static_cast<std::wint_t>(s[lastBreakCharIdx + 1]))
) {
s[lastBreakCharIdx + 1] = '\n';
} else {
s.insert(lastBreakCharIdx + 1, '\n');
}
t.setString(s);
i += 1;
}
if (!std::iswalnum(static_cast<std::wint_t>(s[i]))) {
lastBreakCharIdx = i;
if (i > 0 && isBreakBeforeChar(s[i]))
lastBreakCharIdx -= 1;
}
}
}
示例13: 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);
}
示例14: _choose_color
void _choose_color(sf::Text & text, sf::Vector2f pos, FloatRect & rect){
if (_select_button(pos, rect)){
text.setColor(Color::Yellow);
}
else {
text.setColor(Color::Red);
}
}
示例15: 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);
}