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

Author Topic: Blinking Window  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

Sohil Shrestha7

  • Newbie
  • *
  • Posts: 6
    • View Profile
Blinking Window
« on: May 17, 2013, 01:11:52 pm »
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
« Last Edit: May 17, 2013, 01:26:10 pm by Laurent »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Blinking Window
« Reply #1 on: May 17, 2013, 01:29:44 pm »
Have you even taken a look at your post, after you've pressed "create"? I don't think so... :o
Please edit your post to fix the formatting (no numbers, use code=cpp tag, indent correctly) and keep in mind next time, that this has nothing to do with the SFML C binding, which is the forum you've posted in. ;)

What have you tried up to this point, when trying to fix the problem? Where are you stuck?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Blinking Window
« Reply #2 on: May 17, 2013, 01:39:31 pm »
Please indent your code, and reduce it to a minimal example. Read this thread, ideally all posts of it. This helps you to get appropriate help in the forum.

Also, use loops to avoid the masses of code duplication. Writing the same code for every letter between 'a' and 'z' means you have not understood a basic principle in programming...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Sohil Shrestha7

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Blinking Window
« Reply #3 on: May 17, 2013, 01:49:29 pm »
can anyone help me out here...!!!
i am newbie at this stuff..
i am sorry if i violated any of the forum rules..
i have to submit the project by tomorrow...
help me plz...!!!
the Window keeps blinking...
buffer issues or i dont know..:(

Sohil Shrestha7

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Blinking Window
« Reply #4 on: May 17, 2013, 02:17:35 pm »
@eXpl0it3r

i have created a simple menu... and i was trying to integrate the coded attached part of the program...
but this code seems to keep the screenn blinking. as if the two functions are being constantly called..
newbie...:(