本文整理汇总了C++中sf::Text::setColor方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::setColor方法的具体用法?C++ Text::setColor怎么用?C++ Text::setColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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;
}
}
示例4: _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);
}
}
示例5: rysuj_tekst
void rysuj_tekst( sf::RenderWindow & okno, sf::Color kolor, sf::String _tresc, float x, float y )
{
tekst.setString( _tresc );
tekst.setColor( kolor );
tekst.setPosition( x, y );
okno.draw( tekst );
tekst.setColor( sf::Color::White );
}
示例6: 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);*/
}
示例7: update
void Menupoint::update(sf::Window& window)
{
if (_pos.x <= sf::Mouse::getPosition(window).x &&
_pos.x + _text.getLocalBounds().width >= sf::Mouse::getPosition(window).x &&
_pos.y <= sf::Mouse::getPosition(window).y &&
_pos.y + _text.getLocalBounds().height >= sf::Mouse::getPosition(window).y)
_text.setColor(sf::Color::Blue);
else
_text.setColor(sf::Color::White);
}
示例8: draw_shadow_text
void draw_shadow_text(sf::RenderWindow& window, sf::Text& text, sf::Color color, int x, int y)
{
text.setColor(sf::Color::Black);
text.setPosition(x + 5, y + 5);
window.draw(text);
text.setColor(color);
text.setPosition(x, y);
window.draw(text);
}
示例9: 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);
}
}
示例10: startMenu
bool startMenu(sf::Text title, sf::Text anyKey, sf::Text credits, sf::RenderWindow& window)
{
// create and load texture for earth.png
sf::Texture earth;
if(!earth.loadFromFile("img/earth2.png")) cout << "Error, could not load earth.png" << endl;
sf::Sprite earthSprite;
earthSprite.setTexture(earth);
earthSprite.setPosition(WINDOW_WIDTH / 4 , WINDOW_HEIGHT / 4);
// set title color, position, size and style
title.setColor(sf::Color::Black);
title.setPosition(WINDOW_WIDTH / 5, 0);
title.setCharacterSize(50);
title.setStyle(sf::Text::Bold);
// set anyKey position and color
anyKey.setPosition(WINDOW_WIDTH / 4.5, 410);
anyKey.setColor(sf::Color::Black);
credits.setPosition(WINDOW_WIDTH / 2.6, 450);
credits.setCharacterSize(10);
credits.setColor(sf::Color::Black);
while(window.isOpen())
{
sf::Event event;
while (window.pollEvent(event)) // process events
{
// QUIT
if (event.type == sf::Event::Closed)
{
window.close(); // close the window
return false;
}
// if the user presses any key
if(event.type == sf::Event::KeyPressed || event.type == sf::Event::MouseButtonPressed)
return true;
}
window.clear(sf::Color(255, 255, 235, 0));
window.draw(earthSprite);
window.draw(title);
window.draw(anyKey);
window.draw(credits);
window.display();
}
return false;
}
示例11: 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);
}
示例12:
//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;
}
示例13: showMsg
void showMsg(std::wstring msg, sf::Color foreground) {
if ( (msg.size() * style.fontsize ) > width ) {
msg = linebreak(msg, int(width / style.tilesize));
}
textbox->setString(msg);
textbox->setColor(foreground);
}
示例14: 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();
}
示例15: 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);
}