SFML community forums

Help => Graphics => Topic started by: Sean Mulligan on November 28, 2022, 02:56:08 am

Title: SFML sprites won't be drawn to my render window if they have a negative position
Post by: Sean Mulligan on November 28, 2022, 02:56:08 am
Whenever I try drawing an sfml sprite with a negative position to a render window, it will not display. Is this intentional? If so how do I go around it? If not how do I fix it? Please help, I have been trying to fix this for hours.

Further details:
I am using a view on the window that is provided in an sfml resource on how to allow resizing in a window. It ranges from (0,0) to the window's border
The window is render window, and I am accessing it using a pointer.
The sprite's texture is applied from a variable.
A a texture rect is applied to allow for correct sizing.
Then the sprite's size is set.
Title: Re: SFML sprites won't be drawn to my render window if they have a negative position
Post by: Stauricus on November 28, 2022, 11:01:23 am
the only thing I can think of without further information or any code is that since your view goes from 0,0 to window size, sprites in negative position will be outside the view and therefore will be drawn where they cannot be seen.
Title: Re: SFML sprites won't be drawn to my render window if they have a negative position
Post by: Sean Mulligan on November 28, 2022, 03:52:52 pm
Yes, the sprite is being rendered from a point outside the view to inside the view, so the sprite should be partially seen, but is not rendering at all. I could provide some demo code if you would like.
Title: Re: SFML sprites won't be drawn to my render window if they have a negative position
Post by: Sean Mulligan on November 28, 2022, 08:34:29 pm
Hey, I was debugging my code, and there was nothing wrong with SFML. Turns out I had an issue with signed/unsigned ints messing with the negative values when drawing.

Thank you nonetheless Stauricus for your help. ;) This may be one of the kindest sites on the internet.

----------------------------------ANSWER FOR ANYONE WITH THIS PROBLEM----------------------------------

Please check if your variables are signed and unsigned. This was the cause of the problem for me.
----------------------------------------------------------------------------------------------------------------------
Title: Re: SFML sprites won't be drawn to my render window if they have a negative position
Post by: Stauricus on November 29, 2022, 12:07:10 pm
so afterall it WAS being drawn offscreen  ;D
good thing you fixed it