SFML community forums
Help => Graphics => Topic started by: Pwndja on September 22, 2007, 12:19:18 am
-
here is the code which i am running in my main loop
float width = 0.0;
float height = 0.0;
//window.Display();
for( unsigned int i = 0; i < 60; ++i )
{
for( int j = 0; j < 80; j++)
{
width += 10;
mapSprites[mapInts[j]].SetLeft( width );
mapSprites[mapInts[j]].SetTop( height );
window.Draw( mapSprites[mapInts[j]] );
}
height += 10;
width = 0;
}
i was wondering if there is a better way to draw to the screen or redraw the screen without drawing every sprite over again. So maybe only drawing one sprite that has changed over again instead of redrawing all the sprites over again.
Is there a function which draws just portions of the screen and keeps everything else on the screen?
And if not could that be a feature added in for the next release?
thanks
happy coding
-
To use this kind of redrawing, you must keep in mind all modifications happening on the screen. Thus, it is generaly better to redraw all...
Apart this, your code is very strange for me. Why are you using a unsigned int and a int :
for( unsigned int i = 0; i < 60; ++i )
{
for( int j = 0; j < 80; j++)
{
-
I was using this function with string.size() which returns an unsigned int, and so I used unsigned int to stop linker warnings. but i forgot to change the unsigned int after i had put solid numbers in the for loop.
so what you are saying is it is best to redraw everything and there is no better way to redraw things only when they change?
I would hope that there is a feature which would handle this sort of thing.]
thanks for the response
happy coding.
-
Hop hop hop ! :)
You can draw only changed things, but it can conduct you into somethnig very complex.
With SFML, I think Double-Buffer is used every time, using it will force you to redraw everything.
-
I was using this function with string.size() which returns an unsigned int, and so I used unsigned int to stop linker warnings. but i forgot to change the unsigned int after i had put solid numbers in the for loop.
Actually, that is incorrect. The method string.size() returns an std::string::size_type
It is better to use that rather than an unsigned integer when operating with string.size().
You can simply typedef it shorter if you so wish.