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 - BM

Pages: [1]
1
Sounds logical ! But it wasn't written in the book to add it.

Finaly managed to get that black screen! Thanks a lot.

I'll probably be back sooner than later for more questions!

2
This is Game.h : http://pastebin.com/0D7UuAy5
and the StateManager.h : http://pastebin.com/PpsnL6Kc

You're right, there is no m_context defined in game.h.

3
This is the error I get :

1>c:\c_fun\sfml_5_1\sfml_5_1\game.cpp(9): error C2065: 'm_context': undeclared identifier

that line is  :
Game::Game() : m_window("Chapter 5", sf::Vector2u(800,600)), m_stateManager(&m_context)

4
I don't have a SharedContext.h file. I've defined 
struct SharedContext
{
        SharedContext() : m_wind(nullptr), m_eventManager(nullptr) {}
        Window* m_wind;
        EventManager* m_eventManager;
};

in the BaseState header. Even if I include BaseState.h, the m_context variable stays undefined.

5
Yes, the data member should be:
SharedContext m_context;
It's really weird, because I checked my code submissions, and it's correct there. It must've been "flubbed" during the final stages of the editing process somehow. My apologies.

No worry, it's still immensively helpful.

I've changed all the instances of m_shared to m_context but I still get the m_context is undefined in the game constructor. Do you have any idea as to what might be the problem here?

6
Odd. It may have been taken out, because it's a simple one-liner:
void EventManager::SetCurrentState(StateType l_state){ m_currentState = l_state; }
Sorry about that. Hope this helps!

Ah yea, I was thinking it would be only one line like that.

I still have an error, hopefully the last one before I can get the fabled black screen. On p.109, in the constructor for the game class
Game::Game(): m_window("Chapter 5", sf::Vector2u(800, 600)), m_stateManager(&m_context)

The compiler tells me that m_context is undefined. If I look at the state manager header, there's no m_context member variable either. Is it a typo for
SharedContext* m_shared;
or is it something else?

7
You're right, they are different state classes. You could include them in the StateManager.h file, or even in the .cpp, since the class definition itself doesn't rely on them. The first state "Intro" will be covered on page 110, and will be followed by the rest. For now, you can simply comment those RegisterState<...>(...) lines out, but remember to add them back in once the states are created.

If the problem still persists, please feel free to paste in the errors you're getting. Good luck! :)

I figured it out just as you answered. What threw me off is that on page 110, just before "creating the intro state" section, it says the code should compile to give a black screen. Since it didn't work, I thought that I'd try to get that black screen before continuing on. The good news is that I have another problem!

Still in the state manager, in the SwitchTo method this time. The very first line calls the SetCurrentState method from the event manager class. On p.104, it says the SetCurrentState method will be covered shortly but I can't seem to find it, even by searching the entire document with ctr+f and "SetCurrentState".

8
I've slowly been going over the book and it's been a great help understanding the inner workings of a game. I'm on chapter 5 now at the state manager part, I'm stuck and I can't figure out what's wrong. When I write the constructor for the statemanager class (p100) :

StateManager::StateManager(SharedContext* l_shared)
 : m_shared(l_shared)
{
 RegisterState<State_Intro>(StateType::Intro);
 RegisterState<State_MainMenu>(StateType::MainMenu);
 RegisterState<State_Game>(StateType::Game);
 RegisterState<State_Paused>(StateType::Paused);
}

the compiler doesn't recognize the RegisterState method or any of the <State_***> arguments (which I'm not sure what they're supposed to be at this point, different state classes?). As in the book, I've implemented the RegisterState method in the StateManager header as follow :

template<class T>
void RegisterState(const StateType& type)
{
        m_stateFactory[type] = [this]() -> BaseState*
        {
                return new T(this);
        }
};

9
Have you tried Windows Folder Options and confirm that "Hide extensions for known file types" is not checked?

That was the problem. Thanks a lot !

I knew it was going to be something silly...

10
Is it really called "beach_ball" and not "beach_ball.jpg" or "beach_ball.png"?
Yes, it's really called "beach_ball". But I did try renaming it with the extension and it still wouldn't work. I also tried with a different path.

11
Graphics / sf::Texture::loadFromFile "Reason : Unable to open file"
« on: May 24, 2016, 10:20:56 pm »
I'm unable to load an image using loadFromFile. I keep getting the following message in the console : "Failed to load image "beach_ball". Reason: Unable to open file".

I made sure the working directory is what I think it is (project Properties -> Configuration Properties -> Debugging -> Working Directory) as well as tried with a full path instead like so : C:/C_FUN/SFML_1_1/SFML_1_1/beach_ball. I tried with different pictures and different type of file (png and jpg).

I double checked to make sure that I was using  the proper libraries :-d for debug, no sufix for release.

I'm using windows 7 with VS 2015 and SFML 2.3.2 for Visual C++ 14 (2015) - 64-bit and the project is set to x64.

I've looked around for quite some time before posting this and the main reason was either because the file was not in the right directory or the debug libraries were used for release or vice-versa.

Pages: [1]
anything