hello everybody!
first, i'd like to thank the creator and contributors of this library. it's really easy to understand, and is helping me a lot in learning on how to make a game.
then, i have a question that i believe it's simple.
i have loaded a texture and then created a sprite. this sprite is a tile, so i draw it a lot of times in the screen. then i update the screen, and draw all over again.
the problem is that the screen blinks every time it draws the tiles. (it blinks all tiles at once, and not one at time)
i don't know what could be wrong.
this is how i made it:
#include "head.h"
int main(){
sf::RenderWindow window(sf::VideoMode (480, 480), "Jogo2");
window.setFramerateLimit(60);
Mapa mapa;
mapa.criarMapa();
for (int i = 0; i<100; i++){
window.clear();
mapa.desMapa(&window); //[b]see note below for this[/b]
sf::sleep(sf::milliseconds(10));
window.display();
}
system("pause");
return 0;
}
note: the line mapa.desMapa(&window) draws the tiles on the screen. it does the following:
window->draw(sChaoPedr); //draw the sprite
sChaoPedr.setPosition(mapX*48, mapY*48); //set the sprite position
for each tile.
for some reason, it seems that window.display() clears the screen! after this comand, the screen turns black. i don't know why.
do i have to create one sprite for each tile?
if anyone thinks the error is somewhere else, please let me know, so i'll put the whole code.
i'm working on windows 7 SP1, SFML 2.0rc, Code::Blocks 10.05 (and the default mingw and gcc shipped with it).
thanks in advance :)
There are a few things that have a wrong approache.
You should take a look at the official tutorials (http://www.sfml-dev.org/tutorials/2.0/), the example given in the documentation (http://www.sfml-dev.org/documentation/2.0/) and the examples that come with SFML (https://github.com/SFML/SFML/tree/master/examples). They contain will show you how SFML is intended to use.
Now a few hints:
- You should not have one header file that includes all the header files you'll need, but you should only include the header files you're actually using.
- You should have a normal 'game-loop', i.e. while(window.isOpen()) ...
- The 'game-loop' should have the following order: Handle events, update positions/do calculations, draw entites/sprites.
- The draw should follow the way: clear the window, draw the entites, display them.
- Do not use the system("") function!
Here again an example of a clean loop:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Hello World");
window.setFramerateLimit(60);
sf::Texture texture;
texture.loadFromFile("image.png");
sf::Sprite sprite(texture);
while(window.isOpen())
{
sf::Event event;
while(window.poll(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(sprite);
window.display();
}
}
If this code above also produces blinking/flashing or if any of the examples that ship with SFML are flashing, then it's not SFML fault but your PC's, i.e. is your graphics driver uptodate? Have you some software interfering with graphics? Have you setup some strange video card settings?
for some reason, it seems that window.display() clears the screen! after this comand, the screen turns black. i don't know why.
Since you've set the framerate to 60fps, and you're pausing the application for 10ms every iteration and there are 100 iterations, you're application will stop running after 1-3 seconds and then just show a black screen or similar.
do i have to create one sprite for each tile?
There are diffrent ways to handle tiles, the best solution would be to use a sf::VertexArray.
If you think you did everything right, then you need to post a complete and minimal example that reproduces the problem (see the rules of the forum (http://en.sfml-dev.org/forums/index.php?topic=5559.0)). ;)