XNa game development (iii) -- use isrunningslowly

Source: Internet
Author: User

[Original] Alex
When you use targetelapsedtime to change the screen refresh frequency too high and xNa cannot be reached, gametime. isrunningslowly = true;

Pass the gametime parameter to the update Method to Determine gametime. isrunningslowly

 

Code

Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using Microsoft. xNa. Framework;
Using Microsoft. xNa. Framework. Audio;
Using Microsoft. xNa. Framework. content;
Using Microsoft. xNa. Framework. gamerservices;
Using Microsoft. xNa. Framework. graphics;
Using Microsoft. xNa. Framework. input;
Using Microsoft. xNa. Framework. Media;
Using Microsoft. xNa. Framework. net;
Using Microsoft. xNa. Framework. storage;

Namespace Alex
{
///   <Summary>
/// This is the main type for your game
///   </Summary>
Public   Class Alexgame: Microsoft. xNa. Framework. Game
{
Graphicsdevicemanager graphics;
Spritebatch;

Public alexgame ()
{< br> graphics = New graphicsdevicemanager ( This );
content. rootdirectory = " content " ;
}

///   <Summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// Related content. Calling base. initialize will enumerate through any components
/// And initialize them as well.
///   </Summary>
Protected   Override   Void Initialize ()
{
// Todo: add your initialization logic here
// Set the number of refresh times caused by the ConferenceProgramError
This . Targetelapsedtime = Timespan. fromseconds ( 1.0f   /   24000000f );
Base . Initialize ();
}

///   <Summary>
/// Loadcontent will be called once per game and is the place to load
/// All of your content.
///   </Summary>
Protected   Override   Void Loadcontent ()
{
// Create a new spritebatch, which can be used to draw textures.
Spritebatch =   New Spritebatch (graphicsdevice );

//Todo: Use this. content to load your game content here
}

///   <Summary>
/// Unloadcontent will be called once per game and is the place to unload
/// All content.
///   </Summary>
Protected   Override   Void Unloadcontent ()
{
// Todo: unload any non contentmanager content here
}

///   <Summary>
/// Allows the game to run logic such as updating the world,
/// Checking for collisions, gathering input, and playing audio.
///   </Summary>
///   <Param name = "gametime"> Provides a snapshot of timing values. </Param>
Protected   Override   Void Update (gametime)
{
// Allows the game to exit
If (Gamepad. getstate (playerindex. One). Buttons. Back = Buttonstate. Pressed)
{
This . Exit ();
}
If (Keyboard. getstate (). iskeydown (Keys. Escape ))
{
This . Exit ();
}
// Displayed in the title bar but not running
This . Window. Title = Gametime. isrunningslowly. tostring ();

//Todo: add your update logic here

Base. Update (gametime );
}

///   <Summary>
/// This is called when the game shoshould draw itself.
///   </Summary>
///   <Param name = "gametime"> Provides a snapshot of timing values. </Param>
Protected   Override   Void Draw (gametime)
{
Graphicsdevice. Clear (color. cornflowerblue );

//Todo: add your drawing code here

Base. Draw (gametime );
}
}
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.