c# - How do I pause the redraw in XNA? -


i made xna image viewer, redraws scene, if it's not changing, , it's making netbook burn hell, i'd pause drawing when nothing's changing.

reducing framerate 1 one way keep cool, results in laggy output.

how prevent redraw while there no input?


this problem solved, problem found — game consumes lot of cpu when window in focus, when it's not, takes 1% of cpu. see question details on how solve other problem:

how reduce xna game cpu usage while nothing worth computing happening?

you can use game.supressdraw method purpose. remarks @ link:

call method during update prevent calls draw until after next call update. method can used on small devices conserve battery life if display not change result of update. example, if screen static no background animations, player input can examined during update determine whether player performing action. if no input detected, method allows game skip drawing until next update.

as example, following code call draw function once. when tested noticed cpu usage high (70%) without suppressdraw call. when using supressdraw, cpu usage dropped dramatically (to less 15%). numbers may vary.

public class game1 : microsoft.xna.framework.game {     ...     private bool _drawn = false;     protected override void update(gametime gametime)     {         if (_drawn)             suppressdraw();     }      protected override void draw(gametime gametime)     {         graphicsdevice.clear(color.cornflowerblue);         spritebatch.begin();         /* draw stuff here */         spritebatch.end();          _drawn = true;     }     ... } 

note supressdraw suppresses 1 draw call. prevent more calls draw, have continually call supressdraw in update. makes sense.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -