Boltgreywing Posted July 22, 2017 Share Posted July 22, 2017 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; do { //Input //Update //Render } while(running); } Quote Link to comment Share on other sites More sharing options...
Design1online Posted July 24, 2017 Share Posted July 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Design1online Posted July 24, 2017 Share Posted July 24, 2017 Also, I have an html5 pong tutorial you might find helpful: https://jadendreamer.wordpress.com/2016/02/07/html5-game-tutorial-pong/ 1 Quote Link to comment Share on other sites More sharing options...
Digital Posted August 3, 2017 Share Posted August 3, 2017 @Design1online is correct, it is usually for separation of concerns, and allows for each aspect of your game (input, rendering, and updates) to be separate, thus cleaner. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.