obj\Release\game.o:game.cpp|| undefined reference to `TitleScreen::Show(sf::RenderWindow&)'|
||=== Build finished: 1 errors, 0 warnings ===|
#pragma once
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"
#include <list>
class MainMenu
{
public:
enum MenuResult { Nothing, Exit, Play };
struct MenuItem
{
public:
sf::Rect<int> rect;
MenuResult action;
};
MenuResult Show(sf::RenderWindow& window);
private:
MenuResult GetMenuResponse(sf::RenderWindow& window);
MenuResult HandleClick(sf::Vector2i position);
std::list<MenuItem> _menuItems;
};
#include "titlemenu.h"
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)
{
//Load menu image from file
sf::Texture texture;
texture.loadFromFile("Backgrounds/titlescreen.png");
sf::Sprite sprite(texture);
//Setup clickable regions
//Play menu item coordinates
MenuItem playButton;
playButton.rect.top= 145;
playButton.rect.height = 380;
playButton.rect.left = 0;
playButton.rect.width = 1023;
playButton.action = Play;
//Exit menu item coordinates
MenuItem exitButton;
exitButton.rect.top = 383;
exitButton.rect.height = 560;
exitButton.rect.left = 0;
exitButton.rect.width = 1023;
exitButton.action = Exit;
_menuItems.push_back(playButton);
_menuItems.push_back(exitButton);
window.draw(sprite);
window.display();
return GetMenuResponse(window);
}
MainMenu::MenuResult MainMenu::HandleClick(sf::Vector2i position)
{
std::list<MenuItem>::iterator it;
for ( it = _menuItems.begin(); it != _menuItems.end(); it++)
{
sf::Rect<int> menuItemRect = (*it).rect;
if( menuItemRect.height > position.y
&& menuItemRect.top < position.y
&& menuItemRect.left < position.x
&& menuItemRect.width > position.x)
{
return (*it).action;
}
}
return Nothing;
}
MainMenu::MenuResult MainMenu::GetMenuResponse(sf::RenderWindow& window)
{
sf::Event menuEvent;
sf::Mouse mouse;
sf::Vector2i position = mouse.getPosition(window);
while(42 != 43)
{
while(window.pollEvent(menuEvent))
{
if (mouse.isButtonPressed(mouse.Left))
{
return HandleClick(position);
}
if(menuEvent.type == sf::Event::Closed)
{
return Exit;
}
}
}
}
I can remove the problem by return 1 instead of Handle Click(position);
return HandleClick(position);
Where is the problem ?