How do I show the player's gamer picture?

From XNAWiki
Jump to: navigation, search


To show the player's gamer picture and related gamer profile information, you must first add the GamerServicesComponent component to your game.

// 'this' is your XNA game class
this.Components.Add(new GamerServicesComponent(this));

Next, you can download the player's GamerProfile information by adding two event handlers to catch the player's sign in and sign out events.

SignedInGamer.SignedIn += new EventHandler<SignedInEventArgs>(SignedInGamer_SignedIn);
SignedInGamer.SignedOut += new System.EventHandler<SignedOutEventArgs>(SignedInGamer_SignedOut);
 
void SignedInGamer_SignedIn(object sender, SignedInEventArgs e)
{        
    //do sign in code here    
    GamerProfile profile = e.Gamer.GetProfile();
    Texture2D gamerPicture = profile.GamerPicture;
}
 
void SignedInGamer_SignedOut(object sender, SignedOutEventArgs e)
{
    //do sign out code here
}