using SFML in visual studio 2012 ....
this code gives blinking window.
can anyone tell me how to fix it .. or fix it ..
#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