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

Author Topic: window.draw() does not work inside of 'if' statements  (Read 3194 times)

0 Members and 1 Guest are viewing this topic.

DraGun

  • Newbie
  • *
  • Posts: 21
    • View Profile
window.draw() does not work inside of 'if' statements
« on: August 07, 2015, 04:32:11 pm »
As the title says, whenever I try to use window.draw() inside of an 'if' or 'else' it won't draw. It's something I've had to work around, but now I really just want it to work. Any ideas as to why it doesn't work?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window.draw() does not work inside of 'if' statements
« Reply #1 on: August 07, 2015, 04:37:08 pm »
So let me get this straight, you think we have done something to the draw() function that causes it to fail inside a branch statement? Even if this was remotely possible try to think of a reason that we would do something like that, because it makes no sense at all.

What you need to do is write a complete and minimal example that shows your code and what you are doing wrong so someone can point out what you did wrong.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

DraGun

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: window.draw() does not work inside of 'if' statements
« Reply #2 on: August 07, 2015, 04:42:30 pm »
So let me get this straight, you think I'm assuming that it's your fault that it's broken? Even if that was remotely possible, that doesn't make any sense at all? Why would I just start attacking you? Oh wait, I wasn't.

What you need to do, is not be a complete and total jerk, and realize that I'm asking for help, not starting an attack campaign.

kitteh-warrior

  • Guest
Re: window.draw() does not work inside of 'if' statements
« Reply #3 on: August 07, 2015, 04:49:03 pm »
Maybe if you supplied a minimal and complete example, someone could help you. ::)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window.draw() does not work inside of 'if' statements
« Reply #4 on: August 07, 2015, 04:51:32 pm »
Sorry for being sarcastic, but when you write a post that basically says the following....

(click to show/hide)

doesn't work purely on the fact that there is a branch statement makes no sense whatsoever. So if you believe (according to your post) that any branch statement causes drawing to fail then you clearly did something wrong and are asking for a 'jerk' response. But as I already said, unless you provide code that fails to work with branching statements we can't do anything to help you.

Oh, and for the record: I wasn't attacking you but merely pointing out your flawed reasoning. Following your post you assumed that whenever draw() is used within an 'if' or 'else' statement (branching) that the draw would just fail purely based on the fact it was used with a branch statement.

https://en.wikipedia.org/wiki/Deductive_fallacy
« Last Edit: August 07, 2015, 05:14:04 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: window.draw() does not work inside of 'if' statements
« Reply #5 on: August 07, 2015, 04:52:25 pm »
My 'guess' would be you're doing this:
if (something)
    window.draw(someObject)
else
    window.draw(someOtherObject)
// ...
window.clear();

Looks like zsbzsb beat me to referencing the clear, draw, display...

The above mistake commonly happens when people draw things based on events.
« Last Edit: August 07, 2015, 04:55:54 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DraGun

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: window.draw() does not work inside of 'if' statements
« Reply #6 on: August 07, 2015, 04:59:36 pm »
Well, I figured the first post made it obvious. It's a simple problem, not some complex custom code. The examples you've given is what I'm doing. If you want something specific here:


if (searching == true)
     window.draw(searchText);

 

Whether or not the variable is true, it doesn't draw the text, or rectangle, or sprite, or whatever. My code clears every frame. The trick I've been forced to use to get around this problem is just move the object off screen. It would be a lot simpler if the 'if' statements would work, and would save a couple hundred lines of code.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: window.draw() does not work inside of 'if' statements
« Reply #7 on: August 07, 2015, 05:06:43 pm »
The examples you've given is what I'm doing.
So, you've fixed the problem now?

if (searching == true)
     window.draw(searchText);
Whether or not the variable is true, it doesn't draw the text
That's not true. If searching is true, it will draw searchText.
Is it possible that you've mistyped and the code you use is: if (searching = true)
This is assignment. To avoid this error (if you find you do it often), you could try it the other way around e.g. if (true == searching) or just use
if (searching)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window.draw() does not work inside of 'if' statements
« Reply #8 on: August 07, 2015, 05:07:34 pm »
What you need to do is write a complete and minimal example that shows your code and what you are doing wrong so someone can point out what you did wrong.

Maybe if you supplied a minimal and complete example, someone could help you. ::)

READ ME: http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368

(click to show/hide)
« Last Edit: August 07, 2015, 05:09:54 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything