Hi there,
I'm using CodeBlocks, sfml 2.0, Windows 10.
I'm having some flickering image troubles. If I set the background the image doesn't even appear, if i remove the background the image appears but it flickers.
I show my main and my Graphic class.
#include <iostream>
#include "Card.h"
#include "Special_Card.h"
#include "Deck.h"
#include "time.h"
#include "Graphic.h"
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <string>
#include <vector>
#include <memory>
#include <string>
#include <sstream>
using namespace std;
int main()
{
Graphic * graphic = new Graphic(0);
sf::RenderWindow window;
Deck deck0;
deck0.buildDeck();
graphic->CreateWindow(window, deck0);
}
And this my graphic class definition
#include "Graphic.h"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <string>
#include "Card.h"
#include <string>
#include <sstream>
Graphic::Graphic(int offset)
{
this->offset = offset;
}
int Graphic::CreateWindow(sf::RenderWindow& window, Deck &deck0)
{
sf::Vector2i screenDimensions(800, 600);
//Dimension of Window
window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), "BlackJack", sf::Style::Titlebar | sf::Style::Close);
int index = 0;
window.setKeyRepeatEnabled(false);
//set the background
sf::Texture bTexture;
sf::Sprite bImage;
if(!bTexture.loadFromFile("Background.png"))
std::cout<< "Error" <<std::endl;
bImage.setTexture(bTexture);
bImage.setScale(1.0, (float)screenDimensions.y / bTexture.getSize().y);
//MAIN LOOP----------------------
while(window.isOpen())
{
sf::Event Event;
while(window.pollEvent(Event))
{
switch(Event.type)
{
//chiude la finestra quando premi il tasto chiudi
case sf::Event::Closed:
window.close();
break;
//fa qualcosa quando premi il tasto h sulla tastiera
case sf::Event::KeyPressed:
if(Event.key.code == sf::Keyboard::H)
{
Card * y = deck0.dealFirst();
drawCard(window,y->graphNumber,y->getSeed(),offset); //THIS IS THE FUNCTION WHICH DRAW THE IMAGE
offset = offset + 100;
window.display();
while(window.pollEvent(Event))
{
if( Event.type == sf::Event::Closed)
{
window.close();
}
}
}
break;
}
}
window.draw(bImage); //if I comment this the images appears but they flickers
window.display();
}
}