SFML community forums

Help => General => Topic started by: croux on February 04, 2014, 12:02:07 pm

Title: drawing x coord below 0
Post by: croux on February 04, 2014, 12:02:07 pm
Hi,

i found maybe bug,

this is not working:
s.setPosition( (p.hero_position_x+50-(*window).getSize().x/2) , p.hero_position_y-70+(*window).getSize().y/2 );

this is working:
int dx=(p.hero_position_x+50-(*window).getSize().x/2);
s.setPosition( dx , p.hero_position_y-70+(*window).getSize().y/2 );

When dx is below 0, in first case without temporary variable integer the drawing is not working, but in second case with temporary int the drawing draws. I realized this is weird so I am here to report this issue.

Thanks for answers and sory if I am doing something wrong :)
Title: Re: drawing x coord below 0
Post by: AN71 on February 05, 2014, 05:50:26 am
I'm rather new, so please spare me if I am wrong, but I believe that there may be some sort of implicit type conversions going on. I have no idea what type your hero_position_x is, but the

getSize().x

returns a value with a type of template parameter T, which can be either int or float, though I do not know whether it is unsigned, thus the

(p.hero_position_x+50-(*window).getSize().x/2)

might not be an integer until you declare it as an integer in dx.
Title: Re: drawing x coord below 0
Post by: Jonny on February 05, 2014, 11:43:42 am
What do you mean by 'not working'? it doesn't draw anything? or just draws in the wrong position?

have you debugged? without knowing what s, p, window, etc. are its difficult to help...
Title: Re: drawing x coord below 0
Post by: croux on February 05, 2014, 02:21:32 pm
doesnt draw anything when x<0 ..it just dissappear (while i moving with my hero)... i debugged it..the values are correct but without temporary integer it doesnt work
Title: Re: drawing x coord below 0
Post by: Lo-X on February 05, 2014, 05:17:20 pm
Isn't it because the positions <0 are off-screen ?

Or you mean the whole texte disappear even if some part of it should still be visible ?
Title: Re: drawing x coord below 0
Post by: eXpl0it3r on February 05, 2014, 05:25:11 pm
Does it also not work, if you make the int a float?

As Aeroslizer said, it's most likely an implicit type conversion issue.
Do you get any compiler warnings/have you enabled compiler warnings?
Title: Re: drawing x coord below 0
Post by: croux on February 05, 2014, 11:45:41 pm
its nothing with screen limits bcs this work:
s.setPosition( -50 , p.hero_position_y-70+(*window).getSize().y/2 );

Title: Re: drawing x coord below 0
Post by: croux on February 06, 2014, 12:03:59 am
thanks exploiter... your idea with float helped
it seems there was nonint value in my code bcs with round it is working:
(p.hero_position_x+50-round((*window).getSize().x/2))

same here:

s.setPosition( (p.hero_position_x+50-(int)((*window).getSize().x/2)) , p.hero_position_y-70+(*window).getSize().y/2 );

so its bcs of window.getSize return Vector2u :)


Title: Re: drawing x coord below 0
Post by: Grimshaw on February 06, 2014, 09:16:09 pm
Be really careful with using unsigned integers. If you try to put something <0 in such a variable, it underflows into extremely big numbers.