Changing screen states

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Changing screen states

Post by Musi » January 9th, 2013, 7:00 pm

I've been trying to figure out a way to create separate screens like a title screen, in-game screen, pause screen, etc. I started by just coding everything in the Game class but that got very messy very quickly. Right now I've made each screen its own class and they're gonna be managed by some sort of manager class. I think it will work but i have a feeling i'm doing it all wrong.

Is there a standard way of doing this kind of thing? I have searched but all i seem to find are design patterns that i have no idea how to implement in code.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Changing screen states

Post by LuX » January 14th, 2013, 3:47 pm

I guess any way works and there's no "real" way to do it.

But if a lot of code is involved you might want to put all the "screens" in separate items and then just use a manager to tell what screen to draw and focus on.
ʕ •ᴥ•ʔ

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: Changing screen states

Post by Musi » January 14th, 2013, 5:18 pm

Thanks lux. Turns out there's actually a design pattern called the State Pattern and it basically is just that. Now i'm struggling with the menu system. I've decided to do the same thing, have each menu item be its own object and be managed by a menu manager object.

I've spent so much time on the background logic i havn't even started a game yet, this is maybe overkill for a first game.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: Changing screen states

Post by Clodi » January 16th, 2013, 7:08 pm

"State Pattern" ...right.
I'd like to see Chili doing a video about it. It's soooooo useful for games and apps. in general.

Post Reply