Jump to content

Game pattern

Recommended Posts

Now that I know which loop to use for the game why do people use this pattern? I am kind of confused as why input is separated from update and render in some cases and not combined.

Any one can explain this to me?


//This will be a working pong game.

//It will feature a single paddle, one ball, and three walls.

//It will be played from the left.

//The ball will increase in speed with each time it hits the paddle.

//There is only one life in this game.

//Points are recieved each time the ball hits a wall or the paddle itself.

//The object is to keep the ball above the paddle as long as possible.

//Newer version will have enemies and walls that will emerge from the right wall.

//They will try to attack the player but can only be defeated by the ball.

//Why this pattern for game development?
int main()
   bool running = true;

Link to comment
Share on other sites

It has to do with how computers work and how they draw graphics to a screen. That's what a render function does. They have something called a frame rate, which means how many times the screen re-draws as the monitor refreshes the content that it's displaying. This is also why if you look at a computer screen through a video recording camera lens you can see that the screen appears to flicker.

As far as why you tend to separate input out from rendering -- this has to do with the game state. As you take in input from the user you will update the game state so that the game re-draws things in a manner that makes the graphics appear to be moving. Think of an old timey flip book where you would have to flip through the pages really fast to see the image animate over time. That's the same thing your main game loop is doing, it just has to take into account what the user has done (ie keypress or touch) before it can trigger the game state to update and re-draw everything in an updated position.

You might find it helpful to take some computer graphics or game design classes, they will go into these principals in a much more in-depth way.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...