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

Author Topic: undefined reference to `TitleScreen::Show(sf::RenderWindow&);  (Read 1709 times)

0 Members and 1 Guest are viewing this topic.

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
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 ?
« Last Edit: May 30, 2012, 07:48:45 pm by OutlawLee »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Re: undefined reference to `TitleScreen::Show(sf::RenderWindow&);
« Reply #1 on: May 30, 2012, 08:06:47 pm »
Where is defined TitleScreen::Show?
Laurent Gomila - SFML developer

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
Re: undefined reference to `TitleScreen::Show(sf::RenderWindow&);
« Reply #2 on: May 30, 2012, 10:57:48 pm »
Thanks Laurent, that fixed my problem. Didn't have it all.