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

Pages: 1 ... 3 4 [5] 6 7
61
Can you pastebin your StateManager.h and Game.h files? At this point it looks like you're not defining the m_context data member inside the Game class.

62
Your definition of the SharedContext structure is fine. Move it to SharedContext.h file though. It will be used in many more places later on, and you don't want it sitting inside the BaseState header.

Aside from that, make sure that the SharedContext.h header file is included in the StateManager.h header as well. Try to compile it and paste the error it gives you if it doesn't work.

63
Did you include it in the Game.h header?
#include "SharedContext.h"

64
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.

65
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!

66
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.

It's odd that the compiler doesn't recognize the RegisterState method itself. Make sure it's defined in the StateManager.h file, inside the class as a member function like so:
class StateManager{
public:
  ...
private:
  ...
  template<class T>
  void RegisterState(const StateType& l_type){
    m_stateFactory[l_type] = [this]() -> BaseState*
    {
      return new T(this);
    };
  }
  ...
};
If the problem still persists, please feel free to paste in the errors you're getting. Good luck! :)

67
Ah yes, my suspicion was correct.
And while it is "unnecessary" in this regard, it is as you said a nice way to illustrate how to get a direction, I can see this used for multiple things, (fire back port weapons?)

and oh yea, i did not implement the code, but i see what you mean about the size-1, i always forget that i returns from 1+ and not 0+ as normal counting :)

any ways, still reading and glad to read it all :)
It's an honest mistake. Happens to the best of us, trust me. *cough* Mars Climate Orbiter *cough*.
Either way, please let me know if you have any further concerns, and happy reading! :)

68
You are absolutely correct. However, in order for your code to work, you need to make sure you subtract one from the size of the container:
void Snake::Extend(){
        if (m_snakeBody.empty()){ return; }

        size_t last = m_snakeBody.size() - 1;
        m_snakeBody.push_back(SnakeSegment(
                m_snakeBody[last].position.x, m_snakeBody[last].position.y));
}
It's still a good idea to leave the empty container check in.

The longer segment of the code was intended to more clearly illustrate how the pieces would get positioned in space. I think I was leaning towards taking that out at some point, but I decided to leave it in at the last minute, because I thought it made the positioning more clear. I guess, since you picked up on it, I was at least partially right. :D

69
Thanks a lot for buying it! Yes, one of the most common things people like to bring up about it is the fact that some snippets of code are left out. It's what I had to do during the final draft stage, due to page count limitations. It may not seem like much, but those lines really do start adding up. If I have a chance to fix it up, I will do so in the next edition, as you said. :) The code you brought up in Chapter 3 has already been addressed, by the way. On this very page, northLynx was posting about having the same issue. Keep in mind that if you ever notice missing code pieces from the book, that means they were most likely simple setter/getter methods/functions. You can always consult the code files that came with the book in order to see the complete version with everything intact. Also, I will be watching this thread constantly, so if you have any additional questions, feel free to either shoot me a PM, or simply post here. I will do my best to address your concerns.

Once again, thank you so much for reading, and I hope the rest of it goes smoothly! Keep in touch if you have any more questions.

70
I got to the chapter 4 and now I am having a problem with one of the functions of the eventmanager. I call setfocus in window.cpp but I realized the book never implemented it. Should I know how to implement it? Also, the same with the void togglefullscreen function that was introduced as well in chapter 4.
Sorry about that. If it was emitted in the chapter for whatever reason, you can still find it in the code files that came with the book.
The SetFocus method is actually really simple. All it does is reset a boolean inside the class:
void EventManager::SetFocus(bool l_focus){ m_hasFocus = l_focus; }
ToggleFullscreen method just flips its own boolean that holds the full-screen state, then destroys and re-creates the window:
void Window::ToggleFullscreen(EventDetails* l_details){
        m_isFullscreen = !m_isFullscreen;
        m_window.close();
        Create();
}
Once again, please consult the code files that came with the book, as it should all be included in there. Hope this helps.

71
Yes that did the trick! Now I am getting an error with the float timestep variable the book created. I compared the m_elapsed sf::Time variable I created from chapter 2 and I am assuming the book says that you need to compare that with the float timestep,but it is giving me an error. Is it suppose to give me an error?
The m_elapsed data member should be a float, not sf::Time. That's why it gets compared to another float.
class Game{
...
private:
        ...
        float m_elapsed; // <---
        ...
};
The way it's manipulated is by using the .asSeconds() method of sf::Time when time is being added:
void Game::RestartClock(){ m_elapsed += m_clock.restart().asSeconds(); }
It sounds like you have something mixed up, but it's not the end of the world. You can either adjust your code so that the m_elapsed data member is a floating point number, or simply use .asSeconds() to retrieve a float value from sf::Time. Hope that clears it up a little. If you're still having problems, feel free to send me a PM with your code attached (preferably on pastebin). I will take a look at it and help you out more.

72
I am on the third chapter of the book and followed the code from the book to make the snake game. Right when I call the render functions for the snake and world I realized that that whats passed into the function is not a function that the book made me created. The function is called GetRenderWindow() and its called like *m_window.GetRenderWindow() and passed into the render function like that as well. I checked the chapter again to see if I missed it but I dont see it. Is it something that I need to make because GetRenderWindow is not a function either for the window class.

Oh, I'm so sorry about that. Perhaps an older version of the code has made it into production somehow. Anyway, it's just a simple getter that returns a pointer to the sf::RenderWindow like this:
sf::RenderWindow* Window::GetRenderWindow() { return &m_window; }
Please add that in to the Window class (don't forget to declare it in the header as well), and let me know if it works. Thanks for the feedback! :)

Edit: Come to think of it, it may have even been emitted in order to save some space as well, along with a few other setter/getter methods. Either way, the code files of the book contain everything you will need. Nothing is left out there. :)

73
Can I use this book as my first SFML book? Or should I start with another one?
The book does start off explaining all of the fundamentals. It is also extremely verbose as far as code examples go, so I would say yes. Just make sure you have a decent amount of C++ experience. :)

74
Are we allowed to use the code in the examples however we want or is it just for training?
Feel free to use it in whatever manner you choose. :)

75
That's really weird. It doesn't do that on my end at all, no matter which currency is selected. Either way, Amazon also offers both versions of the book, so you could check that out as well:

http://www.amazon.com/SFML-Development-Example-Raimondas-Pupius-ebook/dp/B01061QAH4/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=&sr=

Pages: 1 ... 3 4 [5] 6 7