本文整理汇总了C++中sf::Text::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::setPosition方法的具体用法?C++ Text::setPosition怎么用?C++ Text::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: Draw
void Scoring::Draw(unsigned int p_num, int score)
{
std::stringstream pointsStream;
pointsStream << score;
points_graphics.setString(pointsStream.str());
switch(p_num)
{
case 0:
points_graphics.setPosition(5,5);
break;
case 1:
points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,5);
break;
case 2:
points_graphics.setPosition(5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5);
break;
case 3:
points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5);
break;
}
WindowManager::Draw(points_graphics);
}
示例5: 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);
}
示例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: 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);
}
示例8: 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();
};
示例9: 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;
}
示例10: 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);
}
示例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);
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();
};
示例12: 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]);
}
}
示例13: draw_on
inline void draw_on(sf::RenderWindow& window)
{
window.draw(circ);
window.draw(sprite);
info_str.setPosition(get_position());
window.draw(info_str);
}
示例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: 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);
}*/
}