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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Scotchdew

Pages: [1]
1
General / Proper way to use classes and user created files
« on: April 17, 2016, 01:12:03 am »
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.

2
General / Help! I'm an idiot (and new) pollEvent()
« on: April 16, 2016, 09:10:49 pm »
Hi, guys. I'm new and a terribly slow learner...learning to program...c++. Great combination. I get hung up on stuff like why functions are given the names they are. For example in the following code I understand everything until I get to where we access the "pollEvent" function.

int main()
{
   sf::Window window;
   window.create(sf::VideoMode(600, 600), "Window");

   while (window.isOpen())
   {
       sf::Event event;
       while (window.pollEvent(event))
       {
           if (event.type == sf::Event::Closed)
            window.close();
       }
   }

}

Being an idiot, and a visual learner, I think of the window object accessing a function called pollEvent. Now when I think of pollEvent, I think of an event where someone is voting...that doesn't make sense to me, so then I research the definition of poll and other than voting, it can be described as a noun being "a head". I am such a dumbass. This doesn't make any sense to me. Can someone explain to me in layman terms why pollEvent is called what it is so I can remember and understand exactly what it does? Thanks guys.

Pages: [1]