Hello,
I'm using SFML 2.0.
I only have three instances of the Text class :
sf::Text heroText("Get of my face ... ");
sf::Text instText("Press 'Space' to speak with people, 'Z' or 'X' to rotate \n and arrows to move");
sf::Text anonyText("?");
However, when I draw those instances like this :
window.draw(heroText);
window.draw(instText);
window.draw(anonyText);
the program at first run slow, but then after like 15 seconds it return to it's normal speed.
So why when I remove the window.draw functions it run at normal speed , but when I use them it run slow at first ?
Ok, here is a part of the game code
you can download the two images ( background and character ) from mediafire
http://www.mediafire.com/?9iiwjt6n6ij5jmi
sorry it's too big for the attachment : )
also I can upload a video on youtube to show you the problem
I'm using Visual C++ 2008, and I'am using dynamic linking
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(900, 550), "SFML works!");
sf::Sprite spriteBg;
sf::Sprite spriteHero;
sf::RectangleShape Rect;
sf::Text heroText("Get of my face ... ");
sf::Text instText("Press 'Space' to speak with people, 'Z' or 'X' to rotate \n and arrows to move");
sf::Text anonyText("?");
sf::Image heroCharCK;
sf::Texture background;
sf::Texture heroChar;
if(!heroCharCK.loadFromFile("heroChar.png")) {
return EXIT_FAILURE;
}
heroCharCK.createMaskFromColor(sf::Color(255, 255, 255), 0);
if(!background.loadFromFile("background.png")) {
return EXIT_FAILURE;
}
if(!heroChar.loadFromImage(heroCharCK)) {
return EXIT_FAILURE;
}
spriteBg.setTexture(background);
spriteBg.setPosition(1.0f, 1.0f);
spriteHero.setTexture(heroChar);
spriteHero.setTextureRect(sf::IntRect(0, 0, 32, 32));
spriteHero.setPosition(600.0f, 200.0f);
Rect.setSize(sf::Vector2f(40, 70));
Rect.setFillColor(sf::Color(41, 14, 152, 200));
Rect.setPosition(100, 100);
heroText.setPosition(spriteHero.getPosition().x + 32, spriteHero.getPosition().y);
heroText.setCharacterSize(15);
heroText.setStyle(sf::Text::Bold);
instText.setPosition(200, 0);
instText.setCharacterSize(15);
instText.setStyle(sf::Text::Bold);
while (window.isOpen()) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
Rect.move(-3, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
Rect.move(3, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
Rect.move(0, -3);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
Rect.move(0, 3);
}
window.clear();
window.draw(spriteBg);
window.draw(spriteHero);
window.draw(Rect);
window.draw(heroText);
window.draw(instText);
window.draw(anonyText);
window.display();
}
return EXIT_SUCCESS;
}
Yes , I was actually using this code :
but I removed it since it's not really useful in this demonstration : )
sf::Event event;
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed) {
window.close();
}
}