就游戏编程而言,我只是一个业余爱好者,但这是我通常做的:
我有一个对象,它代表了游戏中“场景”的一个非常通用的概念。游戏的所有不同主要部分都源自此 Scene 对象。一个场景实际上可以是任何东西,这取决于它是什么类型的游戏。无论如何,从场景派生的每个更具体的场景都有一个为该场景加载所有必要元素的过程。
当游戏要改变场景时,指向活动场景的指针被设置为一个新场景,然后它将加载所有需要的对象。
通用场景对象具有虚拟函数,例如加载、绘制和逻辑,它们在游戏循环中的特定时间从活动场景指针调用。每个特定场景都有自己实现这些方法的方式。
I don't know if that's how it's supposed to be done or not, but it was a very easy way for me to control the flow of things. The scene concept also made it easy to store multiple scenes as collections. With multiple scene pointers stored in a stack of sorts at one time, scenes could be stored in reserve and maintain their full state when returned to, or even do things like dim but to continue to draw while the active scene drew over them as an overlay of sorts.
So anyway, if you do it like that it's not precisely like a web page but I guess if you think about it the right way it's similar enough.