Click here to Skip to main content
Licence CPOL
First Posted 23 Feb 2011
Views 6,525
Bookmarked 7 times

OpenXLive Tutorial 6 : Adding Achievements in WP7 XNA Games

By | 23 Feb 2011 | Article
In this article, we’ll introduce how to use Achievements in games, how to add Achievement to games, and how to award a Achievement.

Introduction

OpenXLive connects gamers on Windows Phone 7 with a social network (SNS) platform, and enables mobile game developers to add social networking features in games with minimal development efforts, including friends, leaderboards, forum, and more. OpenXLive was developed by Fulcrum Mobile Network, Inc. Similar platforms include OpenFeint and Plus+, both of which run on iOS devices.

Image

Background

OpenXLive enables and simplifies the development of social networking features for Windows Phone 7 XNA games. OpenXLive provides gaming community and social network user interface to be integrated into XNA games, which is not supported by Xbox Live.

Using the code

Achievement is a commonly adopted concept in gaming, which is used to promote player sense of accomplishment and keep them interested in the games. Achievements were first introduced by Xbox Live, and later widely adopted in gaming consoles and online gaming. Currently most Achievement implementations are based on cloud services; one example is OpenFeint on iPhone.

Open XLive provides Achievement support which is also based on cloud services. Different than OpenFeint, Achievement in Open XLive is seamlessly integrated with Social Network, and players’ Achievements can be easily shared between friends.

Introduction to Open XLive Achievement

Open XLive Achievement system is independent. In the future we’ll consider integrating it with Xbox Live and/or other platforms. Developers can manage their Achievement system on Open XLive developer website. Players receive certain amount of Points when they obtain new Achievements.

Each game can have up to 200 Achievements, and 1000 Open XLive Points. Developers can allocate Points to each Achievement freely. If all Points have been allocated, no more Achievements can be added.

Players can view Achievements in Open XLive window in the games as well as on Open XLive websites. Select “Achievements” in “Game Center” UI, it will enter the “Achievements” page:

Image

Managing Achievement

To add an Achievement, please make sure you’ve registered at Open XLive website. If not, please refer to “Register Open XLive Developer” <http://wiki.openxlive.com/Tutorial-3-Register-OpenXLive-Developer.ashx>.

Now log on to http://developer.openxlive.com/ using your user name and password. Return to http://developer.openxlive.com/ page, click on “Manage My Game” on the right dashboard, and enter developer “Game Management” page.

In “Game Management” page, find the game you created in the game list.

Image

Click on the name of the game, and enter “Game Details” page:

Image

In “Game Details” page, click on “Achievement”, and enter “Game Achievement” page:

Image

There are more properties for Achievement compared to Leaderboard, but they are not complex.

Name: English and Chinese names are supported.

Open XLive Point: Virtual currency in Open XLive system. Each game can have 1000 Points and 200 Achievements, and each Achievement will require a fixed amount of Points, which cannot be 0.

Max Version and Min Version: Applicable versions for the Achievement. Versions are specified in “Basic Information” page in “Game Management”. If a game version is lower than min version or higher than max version, the Achievement is automatically disabled.

Secret: Specifies if this is a secret Achievement. Secret Achievements will only be displayed in Achievement list after gamer acquires them.

Enabled: Specifies if the Achievement is enabled. Default value is True.

Picture: Specifies the picture of the Achievement. The picture is displayed in Achievement list. Default size is 60x60, and other size pictures will be converted to 60x60 automatically. In the future, user can also choose picture from a built-in list. Please note, the picture should be related to the Achievement.

Description: Description of Achievement in English and Chinese.

HowToEarn: Optional, describes how to earn the Achievement, in English and Chinese.

After we complete Achievement information, click on “Submit”, we can find the Achievement in the Achievement list. Please note down the Achievement ID; we’ll use it in next chapter.

Image

Submitting Achievement

With the Achievement ID, we can submit Achievements in games. We’ll add code to the game logic to submit Achievements.

Before adding code to submit Leaderboard score, please make sure project has references to Open XLive client libraries. Please refer to “Getting Open XLive Getting Started”. <http://wiki.openxlive.com/Tutorial-1-OpenXLive-Getting-Started.ashx>

First, add namespaces for OpenXLive classes:

using OpenXLive;
using OpenXLive.Forms; 

Second, add the following code at the place where Achievements needs to be submitted, calling Award method of Achievement class:

Achievement item = new Achievement(manager.CurrentSession, " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
item.AwardCompleted += new AsyncEventHandler(item_AwardCompleted);
item.Award(); 

We create Achievement instance by calling GameSession.CreateAchievement method. There is only one parameter for the method: Achievement ID, which you can find from Open XLive developer website.

To verify if the Achievement has been submitted successfully, we need to handle AwardCompleted event.

Achievement item = new Achievement(manager.CurrentSession, " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
item.AwardCompleted += new AsyncEventHandler(item_AwardCompleted);
item.Award(); 

Event handler method is as following:

        void item_AwardCompleted(object sender, AsyncEventArgs e)
        {
            if (e.Result.RetureValue)
            {
                // Success
            }
            else
            {
                Debug.WriteLine(e.Result.ErrorMessage);
            }
        } 

Since games won’t be interrupted when Achievements are being retrieved, we don’t recommend using UIs such as MessageBox to display error messages. Instead, we use Debug.WriteLine to display error messages.

Displaying Achievement Rolling News

To make it easier to display retrieved Achievement information, we provide an auxiliary class RollingNewsBoard to help display all retrieved Achievement information.

Here is the rolling news board user interface:

Now we’ll show how to add supports for RollingNewsBoard in our games.

First, add a member of type RollingNewsBoard in derived Game class or DrawableGameComponent class:

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        RollingNewsBoard NewsBoard; 

Second, in LoadContent method, create RollingNewsBoard instance:

        protected override void LoadContent()
        {
            //            NewsBoard = new RollingNewsBoard(manager);  

Third, in Draw method, add Draw method of NewsBoard:

        protected override void Draw(GameTime gameTime)
        {
            if (manager.IsRunning)
            {
                GraphicsDevice.Clear(Color.Black);
                
                spriteBatch.Begin();
                // Draw Something
                NewsBoard.Draw(this.GraphicsDevice, spriteBatch, gameTime);
                spriteBatch.End();
            }
            base.Draw(gameTime);
        } 

Please note, we need to add NewsBoard.Draw method to the end of Draw method, so it won’t be overlapped by other drawing methods. There are 3 parameters for NewsBoard.Draw method: GraphicsDevice of current Game object; SpriteBatch object, used for drawing the UI in the game; GameTime object which is passed into the Draw method.

Fourth, in AwardCompleted event handler, retrieve the RollingNews and add it to NewsBoard. Change event handling method to as follow:

        void item_AwardCompleted(object sender, AsyncEventArgs e)
        {
            if (e.Result.RetureValue)
            {
                // Success
                Achievement item = sender as Achievement;
                if (NewsBoard != null)
                {
                    NewsBoard.AddNews(new RollingNews(item.Name, item.Description, item.Image));
                }
            }
            else
            {
                Debug.WriteLine(e.Result.ErrorMessage);
            }
        } 

RollingNews constructor requires 3 parameters: Title, Description, and Image.

With the code above, when Achievements are submitted successfully, we can display Achievement related information in the game. Besides Achievement information, RollingNews can also display other information, e.g. game bulletin.

View Achievements on Game Websites

We can view Achievements from game official websites.

On the right side of the website, we can see the Achievements panel and the latest Achievement list in the game.

Image

Click on “Achievements”, it’ll take us into detailed information page of Achievements.

Image

What’s the next?

We’ve finished adding Achievements in Open XLive games. So far, we’ve introduced major functionalities of Open XLive services. We’ll continue to show to integrate Open XLive into actual games with two real game examples.

http://wiki.openxlive.com/Real-Game-Examples.ashx

Reference

OpenXLive Website

http://www.openxlive.com/

OpenXLive Developer Website

http://developer.openxlive.com/

Getting Started with Open XLive

http://wiki.openxlive.com/Getting-Started-with-Open-XLive.ashx

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

OpenXLive


Fulcrum Mobile Network, Inc
United States United States

Member

Follow on Twitter Follow on Twitter
OpenXLive connects gamers on Windows Phone 7 with a social network (SNS) platform, and enables mobile game developers to add social networking features in games with minimal development efforts, including friends, leaderboards, forum, and more. OpenXLive was developed by Fulcrum Mobile Network, Inc.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGreat!! PingroupByteStorms23:50 17 Mar '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 23 Feb 2011
Article Copyright 2011 by OpenXLive
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid