Owner.ChangeState(new GameOverState ) Īnd the last state that we have to speak about is GameOverState. Used when player decide to go to menu from pause state Variables used for loading and destroying game content / It shows game view and can load some content related to gameplay. In my example, I have none of the above, so I’ve just left space for it in PrepareState to load, and in DestroyState I left space to destroy not needed content. Game State is just a little different because, in your project, you would need to load some levels or enemies, so there is something to do in your game. And this is true for every other state here. Isn’t it beautiful? On State Start, we are attaching functions to UI events, and they are connected until we change state. / Function called when Quit button is clicked in Menu view. / Function called when Start button is clicked in Menu view. Owner.UI.MenuView.OnQuitClicked -= QuitClicked Owner.UI.MenuView.OnStartClicked -= StartClicked Owner.UI.MenuView.OnQuitClicked += QuitClicked Owner.UI.MenuView.OnStartClicked += StartClicked / Menu state that show Menu view and add interpret user interaction with that view. So what makes that approach so special? Most importantly, logic is implemented on the state-side where it belongs. Rest of the UI scripts are available at the end of the post in public repository. To show you what I mean by that, here is the implementation of MenuView: This practice comes from one of the pillars of MVC, but I’m not going to speak about it now. Their only purpose is to display view and pass user interactions to the states. So first thing before we jump into those states, I’ve implemented UI views to make them as independent as I could.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |