本文整理汇总了C++中sf::Text::setString方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::setString方法的具体用法?C++ Text::setString怎么用?C++ Text::setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::setString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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]);
}
}
示例3: Render
void TextBox::Render(sf::RenderWindow & window)
{
std::string content;
for (auto &itr : _messages) {
content.append(itr + "\n");
}
if (content == "") {
return;
}
_content.setString(content);
window.draw(_backdrop);
window.draw(_content);
}
示例4: draw
// Rendu
void draw(sf::RenderTarget& renderer, const sf::Vector2f& center)
{
sf::Vector2f position(center);
_text.setString(_label);
position.x -= _text.getLocalBounds().width / 2.0f;
position.y -= _text.getLocalBounds().height / 2.0f;
_border.setSize(sf::Vector2f(_text.getLocalBounds().width + 10,
_text.getLocalBounds().height + 10));
_border.setPosition(position);
_text.setPosition(position);
renderer.draw(_text);
renderer.draw(_border);
}
示例5: trimTextToRectangleWidth
void assetHandle::trimTextToRectangleWidth(sf::Text &text, sf::RectangleShape &rect)
{
while(true)
{
sf::FloatRect floatRect = text.getGlobalBounds();
if ((floatRect.left + floatRect.width) > rect.getSize().x)
{
std::string newString = text.getString();
newString = newString.substr(0, newString.size()-1);
text.setString(newString);
}
else
break;
}
}
示例6: init_char_width
void init_char_width(){
if (!PTSANS.loadFromFile("PTN57F.ttf" )) return;
PTSANS_loaded = true;
string tq;
int tmp = log_string.getPosition().x;
for( int i = 255; i--; ){
tq = (char) i;
log_string.setString( tq );
char_width[i] = log_string.findCharacterPos( 1 ).x - tmp;
}
}
示例7: main
int main()
{
sf::Clock clock;
initTexts();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color(244, 67, 54));
if(game_over)
{
window.draw(endText);
ostringstream s;
s << "Your score was : " << snake.length();
scoreText.setString(s.str());
window.draw(scoreText);
}
else
{
input(dir);
sf::Time elapsed = clock.getElapsedTime();
if(elapsed >= delta)
{
if(snake.head()->position() == f.position())
{
snake.add();
f.generatePos();
delta = sf::seconds(delta_i.asSeconds() - (float)snake.length()/100);
}
snake.move(dir);
clock.restart();
}
o.draw();
f.draw();
snake.draw();
}
window.display();
}
return 0;
}
示例8: 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);
}
}
示例9: Setup
void TextBox::Setup(int visible, int charSize, int width, sf::Vector2f screenPos)
{
_numVisible = visible;
sf::Vector2f offset(2.0f, 2.0f);
_font.loadFromFile("arial.ttf");
_content.setFont(_font);
_content.setString("");
_content.setCharacterSize(charSize);
_content.setColor(sf::Color::White);
_content.setPosition(screenPos + offset);
auto backdropHeight = visible * (charSize * 1.2f);
_backdrop.setSize(sf::Vector2f(width, backdropHeight));
_backdrop.setFillColor(sf::Color(90, 90, 90, 90));
_backdrop.setPosition(screenPos);
}
示例10: setAll
void setAll(int& x,int& y,int& xBlock,int& yBlock)
{
x = 375;
y = 250;
if(!font.loadFromFile("ethnocentric rg.ttf"))
{
//error...
};
text = convertInt(score1);
score.setString(text);
score.setFont(font);
score.setCharacterSize(24);
score.setColor(sf::Color(60,60,255));
square.setPosition(x,y);
xBlock = 100;
yBlock = 100;
}
示例11: drawUi
void StateManager::drawUi(sf::RenderTarget& target)
{
Kunlaboro::Message msg(Kunlaboro::Type_Message, NULL, &target);
mSystem.sendGlobalMessage(mRDrawUi, msg);
if (frames++ > 10)
{
prof.setFont(mGlobalFont);
prof.setCharacterSize(12);
char tmp[256];
#ifdef WIN32
sprintf_s(tmp, "Components: %d, entities: %d.\nFPS: %-4d (%.2f avg)\nDT: %-4.2f (%.2f avg)", mSystem.numCom(), mSystem.numEnt(), mTelem->getFPS(), mTelem->getAverageFPS(), mTelem->getDT(), mTelem->getAverageDT());
#else
sprintf(tmp, "Components: %d, entities: %d.\nFPS: %-4d (%.2f avg)\nDT: %-4.2f (%.2f avg)", mSystem.numCom(), mSystem.numEnt(), mTelem->getFPS(), mTelem->getAverageFPS(), mTelem->getDT(), mTelem->getAverageDT());
#endif
prof.setString(tmp);
}
target.draw(prof);
}
示例12: rand
//Enemy constructor.
Enemy(sf::Texture& texture, int x, int y, sf::Font& font) {
mSprite.setTexture(texture);
mRect = sf::FloatRect(x, y, 120, 110); //Character x, y, width, height.
mName = "Enemy";
mTextName.setString(mName);
mTextName.setFont(font);
mTextName.setCharacterSize(30);
mTextName.setStyle(sf::Text::Bold);
mTextName.setColor(sf::Color::Magenta);
mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
mDirection = rand() % 4;
mSpeed = 0.05;
mCurrentFrame = 0;
mAnimationSpeed = mSpeed * 0.05;
mIsAlive = true;
mHP = 100;
mDamage = 30;
}
示例13: setup
void setup(sf::RenderWindow& s, sf::Event& e, sf::Text& t, sf::Font& tf, sf::Text& v, tgui::ListBox::Ptr& res, tgui::ListBox::Ptr& mode, tgui::EditBox::Ptr& c1, tgui::EditBox::Ptr& c2, tgui::Button::Ptr& b, tgui::Gui& sg)
{
tf.loadFromFile("sansation.ttf");
//WINDOW
s.setFramerateLimit(10);
//TITLE
t.setFont(tf);
t.setPosition(-5, 0);
t.setStyle(sf::Text::Underlined);
t.setString(" GRAVITY SIMULATOR ");
t.setCharacterSize(30);
//VERSIONTEXT
v.setFont(tf);
v.setColor(sf::Color(51, 255, 255));
v.setPosition(247, 33);
v.setString("v1.0");
v.setCharacterSize(25);
//GUI
sg.setFont(tf);
sg.add(res);
sg.add(mode);
sg.add(c1);
sg.add(c2);
sg.add(b);
//VIDEOMODE
mode->setScrollbar(nullptr);
mode->setPosition(20, 80);
mode->setItemHeight(15);
mode->setSize(95, 30);
mode->setTextSize(15);
mode->addItem("FULLSCREEN");
mode->addItem("WINDOWED");
mode->setSelectedItemByIndex(0);
//RESOLUTIONS
res->setScrollbar(nullptr);
res->setPosition(20, 115);
res->setItemHeight(15);
res->setTextSize(15);
res->addItem("2560 x 1440");
res->addItem("1920 x 1080");
res->addItem("1366 x 768");
res->addItem("CUSTOM");
res->setSize(95, res->getItemCount() * 15);
//CUSTOM RESOLUTION
c1->setDefaultText("X");
c1->setPosition(125, 140);
c1->setSize(50, 15);
c1->setTextSize(15);
c1->setMaximumCharacters(4);
c2->setDefaultText("Y");
c2->setPosition(125, 160);
c2->setSize(50, 15);
c2->setTextSize(15);
c2->setMaximumCharacters(4);
//STARTBUTTON
b->setPosition(185, 140);
b->setSize(95, 35);
b->setText("START");
b->setTextSize(15);
b->connect("pressed", start, res, mode, c1, c2);
}
示例14: draw_statistics
void draw_statistics(
window& window,
const black_label::path& asset_directory,
const black_label::rendering::pipeline& rendering_pipeline,
bool options_complete )
{
static sf::Font font;
static sf::Text text;
static bool uninitialized{true};
if (uninitialized) {
using namespace black_label;
system::error_code error_code;
auto font_file = canonical_and_preferred("fonts/Vegur-Regular.ttf", asset_directory, error_code);
if (error_code || !font.loadFromFile(font_file.string())) return;
text.setFont(font);
uninitialized = false;
}
gpu::vertex_array::unbind();
gpu::buffer::unbind();
gpu::framebuffer::unbind();
window.window_.resetGLStates();
static bool has_written_message{false};
if (options_complete && rendering_pipeline.is_complete()) {
has_written_message = false;
static unordered_map<string, double> averages;
stringstream ss;
ss.precision(4);
auto output_pass = [&] ( const std::string& name, const chrono::high_resolution_clock::duration& render_duration )
{
if (10s < render_duration || 10us > render_duration) return;
auto render_time = duration_cast<duration<double, milli>>(render_duration).count();
static const double alpha{0.75};
averages[name] = alpha * render_time + (1.0 - alpha) * averages[name];
ss << name << " [ms]: " << render_time << " (" << averages[name] << ")\n";
};
output_pass("rendering_pipeline.json", rendering_pipeline.render_time);
output_pass(
"\t" + rendering_pipeline.shadow_mapping.name,
rendering_pipeline.shadow_mapping.render_time);
auto all_passes = rendering_pipeline.shadow_mapping.render_time;
chrono::high_resolution_clock::duration ldm{0};
for (const auto& pass : rendering_pipeline.passes) {
all_passes += pass.render_time;
if ("ldm" == pass.name.substr(0, 3)) {
ldm += pass.render_time;
continue;
}
output_pass("\t" + pass.name, pass.render_time);
}
output_pass("\tldm (all passes)", ldm);
output_pass("\t(sequencing overhead)", rendering_pipeline.render_time - all_passes);
ss << "data_buffer_size" << " [MB]: " << rendering_pipeline.data_buffer_size * 1.0e-6f << "\n";
ss << "photon_buffer_size" << " [MB]: " << rendering_pipeline.photon_buffer_size * 1.0e-6f << "\n";
text.setString(ss.str());
text.setCharacterSize(16);
text.setColor(sf::Color::Black);
text.setPosition(6, 1);
window.window_.draw(text);
text.setColor(sf::Color::White);
text.setPosition(5, 0);
window.window_.draw(text);
}
else if (!has_written_message) {
has_written_message = true;
auto window_size = window.window_.getSize();
sf::RectangleShape rectangle{sf::Vector2f{window_size}};
rectangle.setFillColor(sf::Color{0, 0, 0, 180});
window.window_.draw(rectangle);
text.setString("Error in rendering config.");
text.setCharacterSize(22);
sf::FloatRect textBounds = text.getLocalBounds();
text.setPosition(sf::Vector2f(
floor(window_size.x / 2.0f - (textBounds.left + textBounds.width / 2.0f)),
floor(window_size.y / 2.0f - (textBounds.top + textBounds.height / 2.0f))));
text.setColor(sf::Color::White);
window.window_.draw(text);
}
}
示例15: setFadeColor
/*
This function changing RGB values of Current Backgorund Color
to new color
@param current color;
@param new color;
@param Handle to window.
@param Handle to font
*/
void setFadeColor(sf::Color ¤tColor, sf::Color &k, sf::RenderWindow &win, sf::Text &font)
{
int tmpR, tmpG, tmpB = 0;
font.setString(points);
/*
config fade for R pat.
*/
if (currentColor.r != k.r)
{
if (currentColor.r > k.r)
{
tmpR = -1;
}
else if (currentColor.r < k.r)
{
tmpR = 1;
}
currentColor.r += tmpR;
font.setColor(currentColor);
}
else
{
tmpR = 0;
}
/*
config fade for G pat.
*/
if (currentColor.g != k.g)
{
if (currentColor.g > k.g)
{
tmpG = -1;
}
else if (currentColor.g < k.g)
{
tmpG = 1;
}
currentColor.g += tmpG;
font.setColor(currentColor);
}
else
{
tmpG = 0;
}
/*
config fade for B pat.
*/
if (currentColor.b != k.b)
{
if (currentColor.b > k.b)
{
tmpB = -1;
}
else if (currentColor.b < k.b)
{
tmpB = 1;
}
currentColor.b += tmpB;
font.setColor(currentColor);
}
else
{
tmpB = 0;
}
font.setColor(currentColor);
win.clear(currentColor);
}