Architecture 基本游戏原型问题

Architecture 基本游戏原型问题,architecture,Architecture,我正在制作一个简单的2d游戏,我想知道是否有一些比我更好的程序员能提出一个设计其基本架构的好方法 这个游戏很简单。屏幕上有许多类型的单元,用于射击、移动和执行命中检测。屏幕可放大和缩小,屏幕侧面有一个菜单UI栏 我现在拥有的架构如下所示: Load a "stage". Load a UI. Have the stage and UI pass references to each other. Load a camera, feed it the "stage" as a parameter.

我正在制作一个简单的2d游戏,我想知道是否有一些比我更好的程序员能提出一个设计其基本架构的好方法

这个游戏很简单。屏幕上有许多类型的单元,用于射击、移动和执行命中检测。屏幕可放大和缩小,屏幕侧面有一个菜单UI栏

我现在拥有的架构如下所示:

Load a "stage".
Load a UI.
Have the stage and UI pass references to each other.
Load a camera, feed it the "stage" as a parameter. Display on screen what the camera is told to "see"

Main Loop {
if (gameIsActive){
   stage.update()
   ui.update()
   camera.updateAndRedraw()
   }
}else{
   if (!ui.pauseGame()){
       gameIsActive=true
   }

if(ui.pauseGame()){
   gameIsActive=false
}


stage update(){
Go through a list of objects on stage, perform collision detection and "action" checks.
objects on stage are all subclasses of an object that has a reference to the stage, and use that reference to request objects be added to the stage (ie. bullets from guns).
}

ui update(){
updates bars, etc. 

}
不管怎样,这都是很基本的。只是好奇是否有更好的方法来做这件事

谢谢,
马修

建造主环路的方法和天空中的星星一样多!你的是完全有效的,可能会很好的工作。以下是一些您可以尝试的东西:

  • 你在哪里读控件?如果您在“ui.update”中执行此操作,然后在“stage.update”中响应,那么您添加了一个滞后框架。确保在循环中按该顺序执行“读取控件->应用控件->更新游戏世界->渲染”

  • 是否使用3D API进行渲染?很多书都告诉您在渲染时(使用OpenGL伪代码)执行类似操作:

    这样做更好

    glSwapBuffers()    // wait for commands from last time to finish
    glClear()          // clear the buffer
    glBlahBlahDraw()   // issue commands
    glFlush()          // start the GPU working
    
    如果这样做,GPU可以在CPU为下一帧更新阶段的同时绘制屏幕

  • 某些游戏引擎即使在游戏“暂停”时也会继续渲染帧并接受某些UI(例如,相机控件)。这允许您在暂停的游戏世界中飞行,并在尝试调试时查看屏幕外的情况。(有时这被称为“调试暂停”,而不是“真正的暂停”。)

  • 此外,许多游戏引擎可以“单步”(运行一帧,然后立即暂停)。如果您试图捕获某个特定事件上发生的错误,这非常方便


希望其中有一些有用-这只是我在查看您的代码时产生的随机想法。

我只编写了一个小游戏,那是几年前的事,所以我不能直接提供很多经验。但是,读了这本书,我可以说它会给你很大的帮助。除此之外,它还有很多关于游戏架构的信息和例子!
glSwapBuffers()    // wait for commands from last time to finish
glClear()          // clear the buffer
glBlahBlahDraw()   // issue commands
glFlush()          // start the GPU working