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

Author Topic: Maintaining background image through window.clear()  (Read 3259 times)

0 Members and 1 Guest are viewing this topic.

lu6cifer

  • Newbie
  • *
  • Posts: 1
    • View Profile
Maintaining background image through window.clear()
« on: June 19, 2013, 02:22:58 am »
I'm very new to SFML, so this question will probably be a bit basic  :P

I'm trying to do some basic animation, so i've created a sprite and everytime i click my mouse, the window will clear the screen with black and redraw the sprite at my mouse position (as far as i know, this is usually how you animate things?)

But the problem comes when i try to use a background image; the window.clear() function only allows me to clear with an RGB color, so upon clearing, the background image gets cleared as well.

I've thought about fixing this by simply loading the background right after clearing, but does SFML have a way to make certain images persist after the frame is cleared?

BlazeTide

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Maintaining background image through window.clear()
« Reply #1 on: June 19, 2013, 02:39:50 am »
Have you tried running the code in a loop? Showing us some sample code would really help.

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Maintaining background image through window.clear()
« Reply #2 on: June 19, 2013, 09:13:38 pm »
At the end of your main program/game loop after everything is updated, all the inputs are handled you are gonna be going

window.clear();

window.draw(background);
//draw anything else after your background if first drawn
window.draw(player);

window.display();
 

there is no way getting around it.  If you don't always clear your screen and redraw everything then you get persistent artifacts visually occurring.

Halsys

  • Jr. Member
  • **
  • Posts: 66
  • Halsys like Hal.sys
    • View Profile
    • Email
Re: Maintaining background image through window.clear()
« Reply #3 on: June 21, 2013, 04:55:37 am »
So let me get this straight.... you are trying to have it where when you click on the screen, the sprite will get drawn so it looks like a animation. Well you could draw the sprite to a render texture and never clear that and then just draw the render texture to the screen instead.

Go ahead and try it out.

On a side note... its not just RGB window.clear supports... it can be actually RGBA.... not sure if the function will even use the alpha channel though... eh *Shrugs shoulders*
If you notice I put "....", in my sentences way too much... I'm sorry.

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Maintaining background image through window.clear()
« Reply #4 on: June 21, 2013, 06:55:27 am »
 
Well you could draw the sprite to a render texture and never clear that and then just draw the render texture to the screen instead.

The problem with that is since the render texture is of the last frame all the last frames sprites are still drawn on it, so you would get the 'mouse trails' effect essentially.  Still gotta have a way to 'clear' the old sprite frames off.  Unless you have a never moving background then you could do it.