How to suppress drawing when mixing Silverlight and XNA on Windows Phone

If your game is paused, or there just isn’t anything happening at the moment (like in between turns in a turn-based game)  you can avoid drawing graphics to save battery.

The old way of doing this in XNA was by calling SuppressDraw() on the Game class. For the mixed XNA/Silverlight template for Windows Phone, there is no Game class available though.

The way to do it is to call the SuppressFrame() method on the GameTimer class, and you do this from your OnUpdate method.

Calling SuppressFrame() will:

Supresses all remaining FrameAction, Update and Draw events from firing this frame for all GameTimers.

 

Silverlight rendering will also be halted!

Take heed if you are drawing anything with Silverlight as this also will be halted when you call SuppressFrame(). This means any currently active story board animations will halt etc.

 

Example code calling SuppressFrame()

     /// <summary>
      /// Allows the page to run logic such as updating the world,
      /// checking for collisions, gathering input, and playing audio.
      /// </summary>
      private void OnUpdate(object sender, GameTimerEventArgs e) {
         // TODO: Add your update logic here
         HandleTouch();
         HandleEvents();
         if (NothingHasUpdated() || IsPaused) {
            GameTimer.SuppressFrame();
         }
      }

Check out some other XNA articles here

XML serialization in the Silverlight / XNA template for Windows Phone 7.1
XNA Error loading content, file not found

SuppressDraw in mixed XNA / Silverlight projects on Windows Phone
Tagged on:         

2 thoughts on “SuppressDraw in mixed XNA / Silverlight projects on Windows Phone

  • October 12, 2011 at 20:08
    Permalink

    I am often to blogging and i really appreciate your content. The article has really peaks my interest. I am going to bookmark your site and keep checking for new information.

    Best regards Alex

    Reply
  • October 22, 2011 at 12:48
    Permalink

    These tips are useful, I will follow these tips. It’s amazing. Thanks for sharing.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.