本文整理汇总了C++中sf::Text::getCharacterSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::getCharacterSize方法的具体用法?C++ Text::getCharacterSize怎么用?C++ Text::getCharacterSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::getCharacterSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
float getStrWidth(sf::Text const &ref)
{
float ret = static_cast<std::string const&>(ref.getString())
.length();
if (ref.getCharacterSize() <= 12)
return ((ref.getCharacterSize() - 4)) * ret;
if (ref.getCharacterSize() >= 20)
return ((ref.getCharacterSize() - 8) * ret);
return ((ref.getCharacterSize() - 5) * ret);
}
示例2: 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]);
}
}
示例3: 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);
}
示例4: 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]);
}
}
示例5: CreateText
Primitive::Ptr Renderer::CreateText( const sf::Text& text, sf::Color background_color_hint ) {
Primitive::Ptr primitive( new Primitive );
const sf::Font& font = text.getFont();
unsigned int character_size = text.getCharacterSize();
sf::Color color = text.getColor();
if( m_preblend ) {
color = sf::Color::White;
}
sf::Vector2f atlas_offset = LoadFont( font, character_size, background_color_hint, text.getColor() );
const sf::String& str = text.getString();
std::size_t length = str.getSize();
float horizontal_spacing = static_cast<float>( font.getGlyph( L' ', character_size, false ).advance );
float vertical_spacing = static_cast<float>( font.getLineSpacing( character_size ) );
sf::Vector2f position( std::floor( text.getPosition().x + .5f ), std::floor( text.getPosition().y + static_cast<float>( character_size ) + .5f ) );
const static float tab_spaces = 2.f;
sf::Uint32 previous_character = 0;
for( std::size_t index = 0; index < length; ++index ) {
sf::Uint32 current_character = str[index];
position.x += static_cast<float>( font.getKerning( previous_character, current_character, character_size ) );
switch( current_character ) {
case L' ':
position.x += horizontal_spacing;
continue;
case L'\t':
position.x += horizontal_spacing * tab_spaces;
continue;
case L'\n':
position.y += vertical_spacing;
position.x = 0.f;
continue;
case L'\v':
position.y += vertical_spacing * tab_spaces;
continue;
default:
break;
}
const sf::Glyph& glyph = font.getGlyph( current_character, character_size, false );
Primitive::Vertex vertex0;
Primitive::Vertex vertex1;
Primitive::Vertex vertex2;
Primitive::Vertex vertex3;
vertex0.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left ), static_cast<float>( glyph.bounds.top ) );
vertex1.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left ), static_cast<float>( glyph.bounds.top + glyph.bounds.height ) );
vertex2.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left + glyph.bounds.width ), static_cast<float>( glyph.bounds.top ) );
vertex3.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left + glyph.bounds.width ), static_cast<float>( glyph.bounds.top + glyph.bounds.height ) );
vertex0.color = color;
vertex1.color = color;
vertex2.color = color;
vertex3.color = color;
// Let SFML cast the Rect for us.
sf::FloatRect texture_rect( glyph.textureRect );
vertex0.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top );
vertex1.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top + texture_rect.height );
vertex2.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top );
vertex3.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top + texture_rect.height );
primitive->AddVertex( vertex0 );
primitive->AddVertex( vertex1 );
primitive->AddVertex( vertex2 );
primitive->AddVertex( vertex2 );
primitive->AddVertex( vertex1 );
primitive->AddVertex( vertex3 );
position.x += static_cast<float>( glyph.advance );
previous_character = current_character;
}
AddPrimitive( primitive );
return primitive;
}
示例6: centerTextPosition
void centerTextPosition( const sf::RectangleShape& rect, sf::Text& text )
{
text.setPosition( rect.getPosition().x + ( rect.getLocalBounds().width / 2 ), rect.getPosition().y + ( rect.getLocalBounds().height / 2 ) - ( text.getCharacterSize() / 2 ) );
}