Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
General
»
No errors, but the window doesnt load anything.
Print
Pages: [
1
]
Author
Topic: No errors, but the window doesnt load anything. (Read 1946 times)
0 Members and 2 Guests are viewing this topic.
Kami
Newbie
Posts: 3
No errors, but the window doesnt load anything.
«
on:
September 11, 2019, 02:52:44 am »
I am trying to make a program for my dads birthday, and learn SFML and C++. I have made everyhting work, then I decided I wanted to make it so the balloons switch colours. I have followed some instructions, and now it doesnt work. here is the code I used
https://pastebin.com/zHjpFZpD
. I just made it so that one side currently switches, then Ill make the other side switch once it works.
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11032
Re: No errors, but the window doesnt load anything.
«
Reply #1 on:
September 12, 2019, 12:37:37 pm »
Can you describe what is not working?
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Kami
Newbie
Posts: 3
Re: No errors, but the window doesnt load anything.
«
Reply #2 on:
September 13, 2019, 06:24:37 am »
Well, It isn't switching the pictures from balloon 4 to balloon 2. I got another code using pointers and it works, but I implemented it into everything and now it doesnt switch the pics. Not on my pc at the moment, so I can't get the new code.
Logged
Arcade
Full Member
Posts: 230
Re: No errors, but the window doesnt load anything.
«
Reply #3 on:
September 13, 2019, 04:04:10 pm »
This looks to be where you're trying to toggle between different balloon sprites, but there are quite a few issues with it.
if
(
elapsed.
asSeconds
(
)
<=
1
)
{
while
(
window.
isOpen
(
)
)
{
activeSprite
=
(
activeSprite
==
&
balloon4Sprite
?
&
balloon2Sprite
:
&
balloon4Sprite
)
;
}
}
This is directly in your main function, not in your main "game loop". You will only hit this if statement one time. You will presumably enter the if statement's body because the time elapsed will likely be under 1 second by this point.
After entering the body of the if statement you will be rapidly switching the sprite back and forth as fast as your CPU can go in the while loop, which is likely not what you want. It seems like you want the if statement to be inside your while loop, not the other way around.
You are never drawing the sprites and displaying the window between each time you toggle the sprite. You will therefore not see anything happen on screen.
You have two of these loops:
while (window.isOpen())
. You are only handling events and drawing things in the second one. You need combine the two loops into one.
«
Last Edit: September 13, 2019, 04:27:42 pm by Arcade
»
Logged
Native Blocks
-
Old School Football Coach
Kami
Newbie
Posts: 3
Re: No errors, but the window doesnt load anything.
«
Reply #4 on:
September 13, 2019, 04:32:12 pm »
I went to reddit first and posted here to be safe, but I am now using pointers and my phone to do it. See my reply above for more info
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
General
»
No errors, but the window doesnt load anything.
anything