Hey guys. I'm going over classes and I'm not sure how I'm supposed to use them. Are classes only supposed to have one job? For example, if I create a class to create a game window, should that class *just* create a game window like this:
#include "window.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
void gameWindow::createWindow()
{
sf::RenderWindow window;
window.create(sf::VideoMode(500, 500), "Move the Ball");
window.display();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
}
I'm creating a game called "Move the Ball" (settle down, you'll get to play it soon enough) and I'm literally just trying to move a ball around in a window but I've already run into a problem. If this window.cpp and window.h strictly has one job to create a window, I can't access the window object from Renderwindow.
window to use in my
ball.cpp to actually draw the ball in this window. Am I doing this right or do I have the idea of uses classes totally wrong? Thanks.