Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Better way to draw to the screen  (Read 4759 times)

0 Members and 1 Guest are viewing this topic.

Pwndja

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Better way to draw to the screen
« 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

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Better way to draw to the screen
« Reply #1 on: September 22, 2007, 08:59:02 am »
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 :
Code: [Select]
for( unsigned int i = 0; i < 60; ++i )
{
for( int j = 0; j < 80; j++)
{
Mindiell
----

Pwndja

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
reason for unsigned int
« Reply #2 on: September 22, 2007, 10:17:11 am »
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.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Better way to draw to the screen
« Reply #3 on: September 22, 2007, 05:25:14 pm »
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.
Mindiell
----

ExcessNeo

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: reason for unsigned int
« Reply #4 on: September 28, 2007, 12:27:53 pm »
Quote from: "Pwndja"
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
Code: [Select]
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.