当前位置: 首页>>代码示例>>C++>>正文


C++ sf::Text类代码示例

本文整理汇总了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);
}
开发者ID:Glowny,项目名称:Korttipelimoottori,代码行数:7,代码来源:DropDown.cpp

示例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);
}
开发者ID:anthonybjturner,项目名称:YasuosQuests,代码行数:26,代码来源:LogMessageWindow.cpp

示例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;
}
开发者ID:abodelot,项目名称:cosmoscroll,代码行数:7,代码来源:SFML_Helper.cpp

示例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);	
		}*/

}
开发者ID:Obscurs,项目名称:genland,代码行数:26,代码来源:Item.cpp

示例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);

	}
开发者ID:dvotf,项目名称:Badass_Tales_Of_Badassland,代码行数:26,代码来源:main.cpp

示例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]);
	}
}
开发者ID:133440,项目名称:Final-Project,代码行数:35,代码来源:Billiards.cpp

示例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;
	}
}
开发者ID:RenatoGeh,项目名称:TryAngle,代码行数:31,代码来源:CustomMenu.hpp

示例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);
}
开发者ID:izissise,项目名称:PFA,代码行数:7,代码来源:Cursor.cpp

示例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;
	}
开发者ID:dvotf,项目名称:Badass_Tales_Of_Badassland,代码行数:30,代码来源:main.cpp

示例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);
}
开发者ID:nathanyoung1,项目名称:spiderkiller,代码行数:9,代码来源:RoundEndScreen.cpp

示例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);
	}
开发者ID:minhoolee,项目名称:id-Tech-Files,代码行数:34,代码来源:Main.cpp

示例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;
        }
    }
}
开发者ID:Oberon00,项目名称:jd,代码行数:29,代码来源:sfUtil.cpp

示例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);
	
}
开发者ID:janderkkotlarski,项目名称:GUI,代码行数:8,代码来源:Top_Down_V0-2.cpp

示例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);
	}
}
开发者ID:Coguar,项目名称:Field964,代码行数:8,代码来源:Menu.cpp

示例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);
}
开发者ID:clavery63,项目名称:tetris,代码行数:8,代码来源:Game.cpp


注:本文中的sf::Text类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。