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

Author Topic: Unnecessary redrawing of sprites and shapes?  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

noodlesgc

  • Guest
Unnecessary redrawing of sprites and shapes?
« on: June 28, 2009, 06:24:29 pm »
Is it possible to create a Sprite, or Shape that is not affected by sf::RenderWindow::Clear?
My reason for asking is that I have an application that draws a background and a number of sprites that will not change throughout gameplay and it feels pointless to clear and redraw them every single loop.
I have used SetFrameRateLimit but is there more I can do?

Thanks

edit:
An example of this would be the Pong.cpp example.
around line 176:
App.Draw(Background);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unnecessary redrawing of sprites and shapes?
« Reply #1 on: June 28, 2009, 06:55:48 pm »
No ;)

But this is never done in real-time rendering. It's just easier and more efficient to clear the whole screen, and redraw everything every loop.

If you have static stuff you'd better put it into a single image.

Quote
An example of this would be the Pong.cpp example.
around line 176:
App.Draw(Background);

This is not the same situation as what you describe. In this case the background would have to be redrawn only at pixels that have been overwritten by other objects. This would be much less efficient than just drawing it entirely.
Laurent Gomila - SFML developer

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Unnecessary redrawing of sprites and shapes?
« Reply #2 on: June 28, 2009, 06:56:56 pm »
What you could do is just draw a rectangle or something around the dynamic sprites (essentially just "clearing" the old position of the sprites) that way you wouldn't have to clear the whole screen (but would have to take into account previous positions, etc.


EDIT: or what you could do is draw the static sprites to an image and then just draw that image over the screen when clearing.

noodlesgc

  • Guest
Unnecessary redrawing of sprites and shapes?
« Reply #3 on: June 28, 2009, 07:46:08 pm »
Quote from: "Laurent"
No ;)

But this is never done in real-time rendering. It's just easier and more efficient to clear the whole screen, and redraw everything every loop.

If you have static stuff you'd better put it into a single image.

Quote
An example of this would be the Pong.cpp example.
around line 176:
App.Draw(Background);

This is not the same situation as what you describe. In this case the background would have to be redrawn only at pixels that have been overwritten by other objects. This would be much less efficient than just drawing it entirely.


So in this example, with no moving objects, the Shapes would not be redrawn since they are not overwritten?

Code: [Select]

from PySFML import sf
import random

window = sf.RenderWindow(sf.VideoMode(800, 600), "Test")

items = []

for x in range(0,100):
    items.append(sf.Shape.Circle(random.randint(0,800),random.randint(0,600),
                 10,sf.Color.Yellow,10,sf.Color.Blue));

running = True

while running:
    event = sf.Event()
    while window.GetEvent(event):
        if event.Type == sf.Event.Closed:
            running = False

    window.Clear(sf.Color(0,0,0))        

    for i in items:
        window.Draw(i)

    window.Display()

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unnecessary redrawing of sprites and shapes?
« Reply #4 on: June 28, 2009, 08:54:49 pm »
No no. I was imagining applying your solution to the pong example.
Laurent Gomila - SFML developer