Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
source to show using number / time with sfml text
Print
Pages: [
1
]
Author
Topic: source to show using number / time with sfml text (Read 3814 times)
0 Members and 1 Guest are viewing this topic.
paulhaggo
Newbie
Posts: 14
source to show using number / time with sfml text
«
on:
November 10, 2014, 09:06:25 pm »
I thought i would post to help others, this works with sfml 2.1 codeblocks c++
#include <SFML/Graphics.hpp>
#include <sstream>
int
main
(
)
{
sf
::
Font
font
;
font.
loadFromFile
(
"arial.ttf"
)
;
sf
::
Text
text
;
text.
setFont
(
font
)
;
text.
setPosition
(
100
,
100
)
;
text.
setCharacterSize
(
34
)
;
text.
setColor
(
sf
::
Color
::
Red
)
;
sf
::
Clock
clock
;
// starts the clock
sf
::
Time
elapsed1
;
// set time object
int
intSecondsCounted
;
std
::
stringstream
ss
;
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
800
,
800
)
,
"Hag"
)
;
// run the main loop
while
(
window.
isOpen
(
)
)
{
// handle events
sf
::
Event
event
;
while
(
window.
pollEvent
(
event
)
)
{
if
(
event.
type
==
sf
::
Event
::
Closed
)
window.
close
(
)
;
}
elapsed1
=
clock
.
getElapsedTime
(
)
;
ss.
str
(
std
::
string
(
)
)
;
//clear the string
ss
<<
elapsed1.
asSeconds
(
)
;
ss
<<
std
::
endl
<<
"Seconds Since I Started Counting"
;
text.
setString
(
ss.
str
(
)
.
c_str
(
)
)
;
window.
draw
(
text
)
;
window.
display
(
)
;
window.
clear
(
)
;
}
return
0
;
}
Logged
G.
Hero Member
Posts: 1593
Re: source to show using number / time with sfml text
«
Reply #1 on:
November 10, 2014, 09:41:56 pm »
Or google "C++ int to string".
Logged
Laurent
Administrator
Hero Member
Posts: 32504
Re: source to show using number / time with sfml text
«
Reply #2 on:
November 10, 2014, 09:57:40 pm »
The Help > Graphics forum is not the right place for this, there's a wiki for users contributions.
And yes, your code only shows how to convert a number to a string, which is basic C++ stuff and not related to SFML at all
Logged
Laurent Gomila - SFML developer
paulhaggo
Newbie
Posts: 14
Re: source to show using number / time with sfml text
«
Reply #3 on:
November 10, 2014, 10:05:41 pm »
point taken, i couldn't get it to work right away, just thought it may help folk, i guess wiki sfml
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 10976
AW: source to show using number / time with sfml text
«
Reply #4 on:
November 10, 2014, 10:35:01 pm »
With C++11 that would just be
std::to_string
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
source to show using number / time with sfml text