Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 207195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:42:50+00:00 2026-05-11T17:42:50+00:00

I’m building a simple 2d game,and I’m wondering if some better coders than I

  • 0

I’m building a simple 2d game,and I’m wondering if some better coders than I can suggest a good way to design its basic architecture.

The game is pretty simple. There are many types of units on the screen which shoot, move, and perform hit detection. The screen zooms in and out, and there is a menu UI bar on the side of the screen.

The architecture I have now looks like this:

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. 

}

Anyway, this is all pretty basic. Just curious if there is a better way to be doing this.

Thanks,
Matthew

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:42:51+00:00Added an answer on May 11, 2026 at 5:42 pm

    There are as many ways of building main loops as there are stars in the sky! Yours is perfectly valid and will probably work fine. Here are some things you might try:

    • Where do you read the controls? If you’re doing it in your “ui.update” and then responding in your “stage.update,” then you’re adding a frame of lag. Make sure you do “read controls -> apply controls -> update gameworld -> render” in that order in your loop.

    • Are you rendering using a 3D API? A lot of books tell you to do something like this when you render (using OpenGL-ish pseudocode):

      glClear()          // clear the buffer
      glBlahBlahDraw()   // issue commands
      glSwapBuffers()    // wait for commands to finish and display
      

      It’s better to do

      glSwapBuffers()    // wait for commands from last time to finish
      glClear()          // clear the buffer
      glBlahBlahDraw()   // issue commands
      glFlush()          // start the GPU working
      

      If you do it that way, the GPU can work on drawing the screen at the same time the CPU is updating the stage for the next frame.

    • Some game engines continue to render frames and accept some UI (for example, camera controls) even when the game is “paused.” This allows you to fly around a paused game world and see what’s going on offscreen when you’re trying to debug. (Sometimes this is called “debug pause” as opposed to “real pause.”)

    • Also, lots of game engines can “single-step” (run one frame, then immediately pause.) That’s very handy if you’re trying to catch a bug that happens on a particular event.

    Hope some of that is helpful – it’s just the random thoughts I had looking at your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.