本文整理汇总了C++中sf::Font类的典型用法代码示例。如果您正苦于以下问题:C++ Font类的具体用法?C++ Font怎么用?C++ Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Font类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LoadFromMemory
bool FontHandler::LoadFromMemory(const typeAssetID theAssetID, sf::Font& theAsset)
{
// Start with a return result of false
bool anResult = false;
// TODO: Retrieve the const char* pointer to load data from
const char* anData = NULL;
// TODO: Retrieve the size in bytes of the font to load from memory
size_t anDataSize = 0;
// TODO: Retrieve the character size for this font
unsigned int anCharSize = 30;
// Try to obtain the font from the memory location specified
if(NULL != anData && anDataSize > 0)
{
// Load the font from the memory location specified
#if (SFML_VERSION_MAJOR < 2)
anResult = theAsset.LoadFromMemory(anData, anDataSize, anCharSize);
#else
anResult = theAsset.loadFromMemory(anData, anDataSize);
#endif
}
else
{
ELOG() << "FontHandler::LoadFromMemory(" << theAssetID
<< ") Bad memory location or size!" << std::endl;
}
// Return anResult of true if successful, false otherwise
return anResult;
}
开发者ID:ItsJackson,项目名称:gqe,代码行数:31,代码来源:FontHandler.cpp
示例2: drawAtributes
void Player::drawAtributes(sf::RenderWindow& rw) const
{
static bool firstRun = true;
static sf::Image tlo;
static sf::Font font;
if(firstRun)
{
tlo.LoadFromFile("Images/tlo.png");
firstRun = false;
font.LoadFromFile("silesiana.otf", 50, L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��[email protected]#$%^&*()_-[]\\;',./{}:\"<>?=-+ ");
}
sf::Sprite tloH(tlo);
rw.Draw(tloH);
std::wstringstream ss;
if(selectedAttribute == 0)
{
ss << L"Exp: " << xp << L"\n";
ss << L"> Poziom obrony: " << defLevel << L"\n";
ss << L"Poziom ataku: " << attLevel << L"\n";
}
else
{
ss << L"Exp: " << xp << L"\n";
ss << L"Poziom obrony: " << defLevel << L"\n";
ss << L"> Poziom ataku: " << attLevel << L"\n";
}
sf::String t(ss.str(), font, 30.f);
t.SetColor(sf::Color(20, 18, 160));
t.SetPosition(20.f, 20.0);
rw.Draw(t);
}
开发者ID:khaiduk,项目名称:rogalik,代码行数:32,代码来源:Player.cpp
示例3: initFonts
/* FontManager::initFonts
* Loads all needed fonts for rendering. SFML 2.x implementation
*******************************************************************/
int FontManager::initFonts()
{
// --- Load general fonts ---
int ret = 0;
// Normal
ArchiveEntry* entry = theArchiveManager->programResourceArchive()->entryAtPath("fonts/dejavu_sans.ttf");
if (entry) ++ret, font_normal.loadFromMemory((const char*)entry->getData(), entry->getSize());
// Condensed
entry = theArchiveManager->programResourceArchive()->entryAtPath("fonts/dejavu_sans_c.ttf");
if (entry) ++ret, font_condensed.loadFromMemory((const char*)entry->getData(), entry->getSize());
// Bold
entry = theArchiveManager->programResourceArchive()->entryAtPath("fonts/dejavu_sans_b.ttf");
if (entry) ++ret, font_bold.loadFromMemory((const char*)entry->getData(), entry->getSize());
// Condensed Bold
entry = theArchiveManager->programResourceArchive()->entryAtPath("fonts/dejavu_sans_cb.ttf");
if (entry) ++ret, font_boldcondensed.loadFromMemory((const char*)entry->getData(), entry->getSize());
// Monospace
entry = theArchiveManager->programResourceArchive()->entryAtPath("fonts/dejavu_mono.ttf");
if (entry) ++ret, font_small.loadFromMemory((const char*)entry->getData(), entry->getSize());
return ret;
}
开发者ID:Monsterovich,项目名称:SLADE,代码行数:30,代码来源:Drawing.cpp
示例4: drawHud
void Player::drawHud(sf::RenderWindow& rw) const
{
static bool firstRun = true;
static sf::Font font;
if(firstRun)
{
firstRun = false;
font.LoadFromFile("silesiana.otf", 50, L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��[email protected]#$%^&*()_-[]\\;',./{}:\"<>?=-+ ");
}
sf::Sprite hud(hudimg, sf::Vector2f(0, 350));
rw.Draw(hud);
int hbarheight= health * hbarimg.GetHeight();
sf::Sprite hbar(hbarimg, sf::Vector2f(42, 376 + hbarimg.GetHeight() - hbarheight));
hbar.SetSubRect(sf::IntRect(0, hbarimg.GetHeight() - hbarheight, hbarimg.GetWidth(), hbarimg.GetHeight()));
rw.Draw(hbar);
std::wstring str;
for(int i=0;i<4;i++)
{
if(i<msgList.size())
str += msgList[i] + L"\n";
}
sf::String msgs(str, font, 30);
msgs.SetColor(sf::Color(120, 10, 10));
msgs.SetPosition(200, 450);
rw.Draw(msgs);
}
开发者ID:khaiduk,项目名称:rogalik,代码行数:29,代码来源:Player.cpp
示例5: LoadFromFile
bool FontHandler::LoadFromFile(const typeAssetID theAssetID, sf::Font& theAsset)
{
// Start with a return result of false
bool anResult = false;
// Retrieve the filename for this asset
std::string anFilename = GetFilename(theAssetID);
// Was a valid filename found? then attempt to load the asset from anFilename
if(anFilename.length() > 0)
{
// Load the asset from a file
#if (SFML_VERSION_MAJOR < 2)
anResult = theAsset.LoadFromFile(anFilename);
#else
anResult = theAsset.loadFromFile(anFilename);
#endif
}
else
{
ELOG() << "FontHandler::LoadFromFile(" << theAssetID
<< ") No filename provided!" << std::endl;
}
// Return anResult of true if successful, false otherwise
return anResult;
}
开发者ID:ItsJackson,项目名称:gqe,代码行数:27,代码来源:FontHandler.cpp
示例6: sizeof
const sf::Font& ResourceManager::getDefaultFont() {
static sf::Font font;
static bool loaded = false;
if (!loaded)
{
static const signed char data[] =
{
#include "Arial.hpp"
};
font.loadFromMemory(data, sizeof(data));
loaded = true;
}
return font;
}
开发者ID:Lirrec,项目名称:SchiffbruchEngine,代码行数:15,代码来源:ResourceManager.cpp
示例7: window
void * init ()
{
sf::Clock sclock;
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
char * font_path;
find_font( &font_path );
if (!MyFont.loadFromFile(font_path))
{
printf("error loading font\n");
}
setup();
draw_hud();
for (int i = 1; i < 6; i++)
add_slot(i);
while (window.isOpen())
{
update(window, sclock);
}
return NULL;
}
开发者ID:dho1,项目名称:Project,代码行数:25,代码来源:hud.cpp
示例8: 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
示例9: Initialize
void Scoring::Initialize()
{
font.loadFromFile("./Resources/Fonts/jokerman.ttf");
points_graphics.setFont(font);
points_graphics.setCharacterSize(24);
points_graphics.setString("0");
}
开发者ID:vsrz,项目名称:VHH,代码行数:7,代码来源:scoring.cpp
示例10: 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);
}
开发者ID:amoshyc,项目名称:sfml-snake,代码行数:26,代码来源:main.cpp
示例11: lire_string
void Param::lire_Texte(std::ifstream &fichier, sf::String &destination, sf::Font &myFont)
{
std::string ligne;
int x, y, z;
lire_string(fichier, ligne);
destination.SetText(traduire(ligne.c_str()));
lire_position(fichier, x, y);
destination.SetPosition(x, y);
lire_string(fichier, ligne);
if(ligne != "default" && !myFont.LoadFromFile(ligne))
{
std::cerr << "Erreur lors du chargement de la police '" << ligne << "'" << std::endl;
myFont = sf::Font::GetDefaultFont();
}
else if(ligne == "default")
myFont = sf::Font::GetDefaultFont();
lire_int(fichier, x);
destination.SetSize(x);
lire_string(fichier, ligne);
set_police(destination, ligne.c_str());
lire_couleur(fichier, x, y, z);
destination.SetColor(sf::Color(x, y, z));
lire_int(fichier, x);
destination.SetRotation(x);
}
开发者ID:Neckara,项目名称:Patcher,代码行数:25,代码来源:Param.cpp
示例12: getText
void ColoredText::getText(unique_ptr_vector<sf::Text>& target, const sf::Font& font, const unsigned char characterSize)const
{
const float TEXT_HEIGHT(font.getLineSpacing(characterSize) + LINE_SPACING);
sf::Vector2f addPosition(0, 0);
target.clear();
getText(target, font, characterSize, TEXT_HEIGHT, addPosition);
}
开发者ID:shtgames,项目名称:GUI-lib,代码行数:8,代码来源:ColoredText.cpp
示例13: render_time
void rendering::render_time(sf::RenderWindow& screen,const GameInfo& stats)
{
static sf::Text text;
static sf::Font f;
f.loadFromFile("../data/Font/Loma.ttf");
text.setFont(f);
text.setColor(sf::Color::Red);
text.setCharacterSize(24);
text.setPosition(700,100);
text.setString(stats.GetFormattedElapsed());
screen.draw(text);
text.setString(std::to_string(stats.getFps()));
text.setPosition(700,125);
screen.draw(text);
}
开发者ID:choupachupss,项目名称:Rogue_BOI_Style,代码行数:18,代码来源:Rendering.cpp
示例14: init
virtual void init()
{
dt=0;
select_switch = 0.2;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
// darken = sf::RectangleShape(sf::Vector2f(800,400));
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))
{
//error
}
blip.setBuffer(buffer);
if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;
tits.setTexture(title);
tits.setOrigin(50,8);
tits.setScale(sf::Vector2f(3,3));
tits.setPosition(400,100);
sf::FloatRect tempt ;
for(int i =0 ; i<4;i++)
{
selector[i].setFont(standard_font);
selector[i].setCharacterSize(28);
// dla centrowania obiektow
tempt = selector[i].getGlobalBounds();
selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
selector[i].setPosition(350,150+30*i);
}
selector[0].setString("Start game");
selector[1].setString("Info");
selector[2].setString("Highscores");
selector[3].setString("Exit");
selector[0].setColor(sf::Color(0,127,127));
timer.restart();
};
开发者ID:TarasJan,项目名称:Sleepwalker,代码行数:56,代码来源:menu.cpp
示例15: initalize
bool initalize(sf::RenderWindow*& rw){
//renderWindow = rw = new sf::RenderWindow(sf::VideoMode(1920, 1080, 32), "SFML", sf::Style::Fullscreen);
renderWindow = rw = new sf::RenderWindow(sf::VideoMode(1280, 720, 32), "NMLB");
drawCalls = frameCount = 0;
cameraX = TARGET_WIDTH / 2;
cameraY = TARGET_HEIGHT / 2;
cameraZ = 1.0f;
return menuFont.loadFromFile(c::fontDir.child("Arial.ttf").path());
}
开发者ID:LEiden94,项目名称:No-Man-Left-Behind,代码行数:11,代码来源:GI.cpp
示例16: FindDefaultFont
namespace OstrichRiders
{
static sf::Font defFont;
static bool init = true;
#ifdef __linux__
std::string FindDefaultFont()
{
std::string answer("/usr/share/fonts/liberation/LiberationSans-Regular.ttf");
FcFontSet *fs;
FcPattern *pat;
FcResult result;
if (!FcInit())
{
return answer;
}
pat = FcNameParse((FcChar8 *)"LiberationSans-Regular.ttf");
FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
fs = FcFontSetCreate();
FcPattern *match;
match = FcFontMatch(0, pat, &result);
if (match)
{
FcChar8 *file;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
{
answer = (const char *)file;
}
FcPatternDestroy(match);
}
FcPatternDestroy(pat);
FcFini();
return answer;
}
#endif
sf::Font &GetDefaultFont()
{
if (init)
{
bool success = defFont.loadFromFile(JOUST_FONT);
if (!success)
{
printf("Failed to load font %s\n", JOUST_FONT);
exit(1);
}
init = false;
}
return defFont;
}
}
开发者ID:LibreGames,项目名称:ostrichriders,代码行数:53,代码来源:defaultfont.cpp
示例17: 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();
};
开发者ID:TarasJan,项目名称:Sleepwalker,代码行数:52,代码来源:jabs.cpp
示例18: 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);
}
开发者ID:Nineshadow,项目名称:Snake-in-C---and-SFML,代码行数:13,代码来源:snake.cpp
示例19: Observer
// Constructeur & destructeur
Observer(const sf::Vector2f& center)
{
//sf::Font font;
assert(_font.loadFromFile("vera.ttf") == true);
_text.setColor(sf::Color::White);
_text.setFont(_font);
_text.setCharacterSize(50);
_text.setStyle(sf::Text::Italic);
_border.setPosition(center);
_border.setOutlineColor(sf::Color::White);
_border.setOutlineThickness(2.0);
_border.setFillColor(sf::Color::Transparent);
}
开发者ID:xeloni,项目名称:ProjetsClion,代码行数:14,代码来源:observer.hpp
示例20: 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();
};
开发者ID:TarasJan,项目名称:Sleepwalker,代码行数:51,代码来源:wingame.cpp
注:本文中的sf::Font类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论