Blinking Window in SFML

using SFML in visual studio 2012 ....
this code gives blinking window.
can anyone tell me how to fix it .. or fix it ..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include<iostream>
#include<SFML\Graphics.hpp>
using namespace std;
sf::RenderWindow window (sf::VideoMode(800,600),"GAME");

char original[5]=" cat";
char repeated[27]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
int i=0;
int lengthcheck();
int repeatcheck(char a);
float positioncheck(char c);
int lengthcheck()
{
int length=1;
while(original[i]!='\0')
{

length+=1;
i=i+1;
}
return length;
}


float positioncheck(char c)
{
float temp=0;
for(int i=0;i<4;i++)
{
if (original[i]==c)
{
temp=(float)i;
return temp;
}
}
return 0;
}
void storerepeat(char a)
{
repeated[i]=a;
i=i+1;
}
int repeatcheck(char a)
{
for(int j=0;j<27;j++)
{
if(a== repeated[j])

return 1;
}
storerepeat(a);
return 0;
}
void gamef()
{
window.setKeyRepeatEnabled(false);
sf::Text charact;
char character=' ';
int returned=-1;
bool start=true;
sf::Event event;
while (start== true)
{
while(window.pollEvent(event))
{
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::C )
{

character='c';
returned=repeatcheck('c');

}

if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::A )
{
character='a';
returned=repeatcheck('a');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::B )
{
character='b';
returned=repeatcheck('b');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::D )
{
character='d';
returned=repeatcheck('d');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::E )
{
character='e';
returned=repeatcheck('e');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::F )
{
character='f';
returned=repeatcheck('f');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::G )
{
character='g';
returned=repeatcheck('g');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::H )
{
character='h';
returned=repeatcheck('h');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::I )
{	
character='i';
returned=repeatcheck('i');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::J )
{
character='j';
returned=repeatcheck('j');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::K )
{
character='k';
returned=repeatcheck('k');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::L )
{
character='l';
returned=repeatcheck('l');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::M )
{
character='m';
returned=repeatcheck('m');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::N)
{
character='n';
returned=repeatcheck('n');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::O )
{
character='o';
returned=repeatcheck('o');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::P )
{
character='p';
returned=repeatcheck('p');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Q )
{
character='q';
returned=repeatcheck('q');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::R )
{
character='r';
returned=repeatcheck('r');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::S)
{
character='s';
returned=repeatcheck('s');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::T )
{
character='t';
returned=repeatcheck('t');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::U )
{
character='u';
returned=repeatcheck('u');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::V )
{
character='v';
returned=repeatcheck('v');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::W )
{
character='w';
returned=repeatcheck('w');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::X )
{
character='x';
returned=repeatcheck('x');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Y )
{
character='y';
returned=repeatcheck('y');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Z )
{
character='z';
returned=repeatcheck('z');
}

}
if (returned==1)
{
cout<<"repeated";
}
else if(returned==0)
{
float position=positioncheck(character);
cout<<position;
if(position!=0)
{
float posi=0;
posi=position*100;
charact.setString(character);
charact.setPosition(sf::Vector2f(posi,350));
window.draw(charact);
}	
}
returned=-1;
window.display();
}

window.close();
}


int main()
{
sf::RectangleShape underscore;
underscore.setPosition(100,400);
underscore.setSize(sf::Vector2f(50,5));
underscore.setFillColor(sf::Color::Blue);
float x=0;

int length=lengthcheck();
cout<<length;
for(int i=0;i<length;i++)
{

window.draw(underscore);
underscore.setPosition(100+x,400);
x=x+70;
}
gamef();


return 0;
}


THANKS IN ADVANCE
Last edited on
sry the code are these

#include<iostream>
#include<SFML\Graphics.hpp>
using namespace std;
sf::RenderWindow window (sf::VideoMode(800,600),"GAME");

char original[5]=" cat";
char repeated[27]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
int i=0;
int lengthcheck();
int repeatcheck(char a);
float positioncheck(char c);
int lengthcheck()
{
int length=1;
while(original[i]!='\0')
{

length+=1;
i=i+1;
}
return length;
}


float positioncheck(char c)
{
float temp=0;
for(int i=0;i<4;i++)
{
if (original[i]==c)
{
temp=(float)i;
return temp;
}
}
return 0;
}
void storerepeat(char a)
{
repeated[i]=a;
i=i+1;
}
int repeatcheck(char a)
{
for(int j=0;j<27;j++)
{
if(a== repeated[j])

return 1;
}
storerepeat(a);
return 0;
}
void gamef()
{
window.setKeyRepeatEnabled(false);
sf::Text charact;
char character=' ';
int returned=-1;
bool start=true;
sf::Event event;
while (start== true)
{
while(window.pollEvent(event))
{
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::C )
{

character='c';
returned=repeatcheck('c');

}

if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::A )
{
character='a';
returned=repeatcheck('a');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::B )
{
character='b';
returned=repeatcheck('b');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::D )
{
character='d';
returned=repeatcheck('d');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::E )
{
character='e';
returned=repeatcheck('e');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::F )
{
character='f';
returned=repeatcheck('f');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::G )
{
character='g';
returned=repeatcheck('g');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::H )
{
character='h';
returned=repeatcheck('h');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::I )
{
character='i';
returned=repeatcheck('i');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::J )
{
character='j';
returned=repeatcheck('j');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::K )
{
character='k';
returned=repeatcheck('k');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::L )
{
character='l';
returned=repeatcheck('l');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::M )
{
character='m';
returned=repeatcheck('m');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::N)
{
character='n';
returned=repeatcheck('n');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::O )
{
character='o';
returned=repeatcheck('o');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::P )
{
character='p';
returned=repeatcheck('p');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Q )
{
character='q';
returned=repeatcheck('q');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::R )
{
character='r';
returned=repeatcheck('r');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::S)
{
character='s';
returned=repeatcheck('s');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::T )
{
character='t';
returned=repeatcheck('t');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::U )
{
character='u';
returned=repeatcheck('u');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::V )
{
character='v';
returned=repeatcheck('v');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::W )
{
character='w';
returned=repeatcheck('w');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::X )
{
character='x';
returned=repeatcheck('x');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Y )
{
character='y';
returned=repeatcheck('y');
}
if(event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Z )
{
character='z';
returned=repeatcheck('z');
}

}
if (returned==1)
{
cout<<"repeated";
}
else if(returned==0)
{
float position=positioncheck(character);
cout<<position;
if(position!=0)
{
float posi=0;
posi=position*100;
charact.setString(character);
charact.setPosition(sf::Vector2f(posi,350));
window.draw(charact);
}
}
returned=-1;
window.display();
}

window.close();
}


int main()
{
sf::RectangleShape underscore;
underscore.setPosition(100,400);
underscore.setSize(sf::Vector2f(50,5));
underscore.setFillColor(sf::Color::Blue);
float x=0;

int length=lengthcheck();
cout<<length;
for(int i=0;i<length;i++)
{

window.draw(underscore);
underscore.setPosition(100+x,400);
x=x+70;
}
gamef();


return 0;
}
You have not initialized q that you use to calculate the position of charact.
i was trying to solve it..
check the second code plz....
Need urgent help on this...
have to submit project by next week...
Can anybody help..
Plzasap
You need to pause the program before it exits. Add #include <SFML\System.hpp> (I think) and put sf::sleep( sf::seconds( 3.0f ) ); before the return 0 statement in main(). This will make the window stay open for 3 seconds before closing.

Looked at the wrong code :/
Last edited on
But he's using a loop loop ...

What exactly do you mean by blinking window. Can you describe it for me because I don't have SFML installed so I can't test it myself.
I think the main() function and gamef() function are constantly being called ...
If i press C , it keeps blinking...
In my orginal project, the background has 2 pictures and they keeping switching
Continuously...
But the program does take input and display what needs to be..
The only problem is it keeps blinking(switching i guess)
not working...
would appreciate any help...
Topic archived. No new replies allowed.