Classe Game
#include "Game.h"
Game::Game()
{
sf::RenderWindow window(sf::VideoMode(WIDTH_WINDOW, HEIGHT_WINDOW), "[V0.01]Relation SFML", sf::Style::Default);
window.setKeyRepeatEnabled(true);
window.setFramerateLimit(200);
Event event1;
GUI gui;
while (window.isOpen())
{
gui.Time();
gui.Update(&window);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(gui);
window.display();
}
}
#ifndef GAME_H
#define GAME_H
#include <cstdlib>
#include <time.h>
#include <SFML/Graphics.hpp>
#include "GUI/GUI.h"
#define WIDTH_WINDOW 800
#define HEIGHT_WINDOW 600
class Game
{
public:
Game();
private:
};
#endif // GAME_H
Classe Button (où j'ai enlevé toutes les fonctions pour définir la taille, la couleur etc)
#include "Button.h"
Button::Button()
{
if (!font.loadFromFile("Resources/arial.ttf"))
{
std::cout << "erreur font" << std::endl;
}
text_button.setFont(font);
rect_button.setSize(sf::Vector2f(100, 100));
rect_button.setFillColor(sf::Color::Red);
}
Button::~Button()
{
//dtor
}
#ifndef BUTTON_H
#define BUTTON_H
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
class Button : public sf::Drawable, sf::Transformable
{
public:
Button();
virtual ~Button();
protected:
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw(rect_button, states);
}
sf::RectangleShape rect_button;
sf::Font font;
};
#endif // BUTTON_H
Classe GUI
#include "GUI.h"
GUI::GUI()
{
if(!font.loadFromFile("Resources/arial.ttf"))
cout << "Error LOADING FONT" << endl;
}
void GUI::Update(sf::RenderWindow*window)
{
target->draw(b_menu);
}
#ifndef GUI_H
#define GUI_H
#include <iostream>
#include <sstream>
#include <SFML/Graphics.hpp>
#include "Button.h"
using namespace std;
class GUI : public sf::Drawable, sf::Transformable
{
public:
GUI();
void Update(sf::RenderWindow *Window);
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
}
Button b_menu;
sf::Font font;
};
#endif // GUI_H