Search code examples
c#windows-phone-7xnaxna-4.0game-loop

XNA - Update method vs Draw method


I am very much interested to know, what if i put all sprite animation/movement logic inside the Draw method instead of Update method and update method is just manage the touch and other events. 1) any issues with performance of the game animation/logic?
2) will game screen not act as expected ?


Solution

  • There is basically one big difference between the draw and update methods. The draw method runs in cycles with the performance of the machine, so if the computer is slow, you might get 30 cycles each second if the computer has low performance. This also means that the cycles are not fixed, so one second you might get 30 cycles from the draw method, and the next time you might get 40.

    The update method has a fixed number of cycles instead, so this means that the gameplay will not slow down just because the computer is slow.

    It is not a problem to put the sprite animation logic inside the draw method. This will simply mean that the animation will run at the speed of what the machine can handle. However, if the animation affects other logic directly in the game, I would recommend putting the code in the update thread.