Hi again,
Think is a graphics issue? Actually got some time to start looking more indepth into SFML 2.0, and was running through some guides and tutorials. I ended up merging a few bits I found to try make something without the aid of the guides completely. However this might be where my errors occurred, I'm trying to get a simple bit of text to display in the window. I've searched these forums and Google, to no avail really. The program runs fine, no errors but the text is simply not there? Maybe another simple issue but I'd love a point in the right direction :D
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
using namespace sf;
int main()
{
VideoMode videoMode(320,240);
RenderWindow window(videoMode,"KeyEvent Window");
//Set objects in the window
sf::Font font;
font.loadFromFile("Fonts\BRADHTC.ttf");
sf::Text text;
text.setString("Hello");
text.setFont(font);
text.setCharacterSize(2);
text.setPosition(30, 30);
text.setColor(sf::Color::Black);
RectangleShape rectangle;
rectangle.setPosition(30,30);
rectangle.setSize(Vector2f(50, 30));
rectangle.setFillColor(Color::Green);
rectangle.setOutlineColor(Color::White);
rectangle.setOutlineThickness(3);
//
while (window.isOpen())
{
window.clear(sf::Color::White);
window.draw(text);
window.draw(rectangle);
window.display();
Event event;
while (window.pollEvent(event))
{
if ( (event.type == Event::Closed) ||
((event.type == Event::KeyPressed) && (event.key.code==Keyboard::Escape)) )
window.close();
else
{
if (event.type == Event::KeyPressed)
{
switch(event.key.code)
{
case Keyboard::Up: rectangle.move(0, -10);
break;
case Keyboard::Down: rectangle.move(0, 10);
break;
case Keyboard::Left: rectangle.move(-10, 0);
break;
case Keyboard::Right: rectangle.move(10, 0);
break;
}
}
}
}
}
return EXIT_SUCCESS;
}
If any of this code is a bit messy or unneeded, feel free to point that out aswell but I am still grasping this so don't know all the best ways to do things yet :P
Thanks to anyone who reads this..
You are first drawing the text and then the rectangle. So even if the text would be drawn, you draw the rectangle over it.
Also check the loadFromFile line.
font.loadFromFile("Fonts\BRADHTC.ttf");
Backslash is an escape character. You need to replace it with '/' or with '\\' to make it work.
Edit: And isn't a character size of 2 pixels a little small for a text?
You are first drawing the text and then the rectangle. So even if the text would be drawn, you draw the rectangle over it.
Also check the loadFromFile line.
font.loadFromFile("Fonts\BRADHTC.ttf");
Backslash is an escape character. You need to replace it with '/' or with '\\' to make it work.
Edit: And isn't a character size of 2 pixels a little small for a text?
I've tried it both ways and the text doesn't display when its before or after the rectangle. Also its size 2 as I was playing around with the size incase it was outside the window or something. It doesn't appear at any size :(
I changed the backslash to both / and \\ and it doesn't show either