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

Author Topic: drawing x coord below 0  (Read 3220 times)

0 Members and 1 Guest are viewing this topic.

croux

  • Newbie
  • *
  • Posts: 15
    • View Profile
drawing x coord below 0
« 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 :)

AN71

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: drawing x coord below 0
« Reply #1 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.
Quote from: Friedrich Nietzsche
He who would learn to fly one day must first learn to stand and walk and run and climb and dance; one cannot fly into flying.

Jonny

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • Email
Re: drawing x coord below 0
« Reply #2 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...

croux

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: drawing x coord below 0
« Reply #3 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

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: drawing x coord below 0
« Reply #4 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 ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: drawing x coord below 0
« Reply #5 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

croux

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: drawing x coord below 0
« Reply #6 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 );

« Last Edit: February 05, 2014, 11:47:19 pm by croux »

croux

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: drawing x coord below 0
« Reply #7 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 :)


« Last Edit: February 06, 2014, 12:10:30 am by croux »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: drawing x coord below 0
« Reply #8 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.