#include "stdafx.h"
#include "EventHandling.h"
EventHandling::EventHandling()
{
}
EventHandling::~EventHandling()
{
}
void EventHandling::HandleEvents()
{
// But while it is in main, this dosen't work
while (window.IsOpen())
{
// Event Handling
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
switch (event.key.code)
{
case sf::Keyboard::Escape:
window.close();
break;
}
}
}
}
}
EventHandling.h
1 2 3 4 5 6 7 8 9 10
#pragma once
class EventHandling
{
public:
EventHandling();
~EventHandling();
void HandleEvents();
};
All you want to do, is create the window, which is what this does. Then nothing more, the window is there until you close it, that's why you put it as basically the very first thing.
#include "stdafx.h"
#include "EventHandling.h"
EventHandling::EventHandling()
{
}
EventHandling::~EventHandling()
{
}
void EventHandling::HandleEvents()
{
// But while it is in main, this dosen't work
while (window.IsOpen())
{
// Event Handling
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
switch (event.key.code)
{
case sf::Keyboard::Escape:
window.close();
break;
}
}
}
}
}
Error 2 error C2065: 'window' : undeclared identifier c:\users\dylan\documents\visual studio 2013\projects\tile mapping game\eventhandling.cpp 14 1 Tile Mapping Game
Error 3 error C2228: left of '.IsOpen' must have class/struct/union c:\users\dylan\documents\visual studio 2013\projects\tile mapping game\eventhandling.cpp 14 1 Tile Mapping Game
Error 5 IntelliSense: identifier "window" is undefined c:\Users\Dylan\Documents\Visual Studio 2013\Projects\Tile Mapping Game\EventHandling.cpp 14 9 Tile Mapping Game
Ofc your code doesnt work. Window is not defined in that class. You're gonna have to send it in via the function parameters to be able to access it in your function.
Error 2 error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable' c:\users\dylan\documents\visual studio 2013\projects\tile mapping game\sfml-2.3.2\include\sfml\window\window.hpp 521 1 Tile Mapping Game
Error 3 error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable' c:\users\dylan\documents\visual studio 2013\projects\tile mapping game\sfml-2.3.2\include\sfml\graphics\rendertarget.hpp 419 1 Tile Mapping Game