SFML community forums

Help => Graphics => Topic started by: lu6cifer on June 19, 2013, 02:22:58 am

Title: Maintaining background image through window.clear()
Post by: lu6cifer 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?
Title: Re: Maintaining background image through window.clear()
Post by: BlazeTide 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.
Title: Re: Maintaining background image through window.clear()
Post by: The Hatchet 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.
Title: Re: Maintaining background image through window.clear()
Post by: Halsys 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*
Title: Re: Maintaining background image through window.clear()
Post by: The Hatchet 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.