Why is a “main” game loop necessary for developing a game?

前端 未结 11 1914
自闭症患者
自闭症患者 2020-12-23 13:52

I find that most game development requires a main game loop, but I don\'t know why it\'s necessary. Couldn\'t we implement an event listener and respond to every user action

11条回答
  •  忘掉有多难
    2020-12-23 14:18

    Two reasons -

    Even event driven systems usually need a loop of some kind that reads events from a queue of some kind and dispatches them to a handler so you end up with an event loop in windows for example anyway and might was well extend it.

    For the purposes of animation you'd need to handle some kind of even for every frame of the animation. You could certainly do this with a timer or some kind of idle event, but you'd probably end up creating those in some kind of loop anyway so it's just easier to use the loop directly.

    I've seen systems that do handle it all using events, they have a frame listener that listens to an event dispatched at the start of each frame. They still have a tiny game loop internally but it does little more than handle windowing system events, and create frame events,

提交回复
热议问题