XNA Documentation
From J2Play
|
Add Toolkit
This tutorial explains how to add J2Play features to XNA games.
Prerequisites
- The gameID got from Step 1: Setup_your_game
- Familiar with Visual Studio 2005 or later
- Some XNA knowledge
Download Toolkit
- J2Play Toolkit for XNA Image:J2play-csharp-toolkit.zip
Preparation
- Extract the XNA toolkit package, copy all files to your output directories, it usually is your_project_directory/bin/x86/debug and your_project_directory/bin/x86/release
Initializing the INI File
You should now have all of the J2Play dependencies within your program's executable directory. The final step in getting your game to talk to the J2Play playground involves modifying the j2play.ini file.
Within the j2play.ini file, you should have the following values:
[GameTemplate] templateName=default playernum= [SystemInfo] IP=production.j2play.net port=4501 GameID=0 NetworkID=@J2PLAY_NETWORK@ UserAgent="J2PlayGDK" HasServer = 0 [Facebook] facebook_userGUID=@J2PLAY_GUID@ facebook_screenname=@J2PLAY_SCREENNAME@ facebook_params=@FACEBOOK_PARAMS@
We only care about the bolded elements.
- playerNum: The number of players your game supports.
- GameID: The ID of your game
Following information can be retrieved from J2Play Facebook Developer App in http://apps.facebook.com/j_devapp
- NetworkID: The network your game runs on (in this case we'll use Facebook).
- facebook_userGUID: Your facebook GUID.
- facebook_screenname: Your desired facebook screen name.
- facebook_params: Example: ?userid=<GUID>&screenname=<screen name>&networkid=<networkid>&gameid=<gameid>&imageurl=<profile picture>
Using J2Play GDK Wrapper in your game
It includes 3 essential steps: 1)Init/Uninit GDK; 2)Embed Community; 3)Close Community. Besides, use notifications to synchronize the operations between the community and the game.
Init and uninit J2play GDK
Add following code to your Main() function in class Program, replace the code of game.Run();
J2Play.GDKWrapper gdk=J2Play.GDKWrapper.GetInstance();
gdk.Init();
IWin32Window pwin = gdk.CreateGameCommunity("Your game name", "", new System.Drawing.Rectangle(0, 0, 0, 0));
if (pwin != null)
{
game.Run();
}
gdk.Uninit();
J2Play.GDKWrapper.GetInstance()
Get the singleton object of GDKWrapper for .net
J2Play.GDKWrapper.Init()
Init the J2Play GDK library
J2Play.GDKWrapper.Uninit()
Uninit the J2Play GDK library
J2Play.GDKWrapper.CreateGameCommunity()
Create j2play game community
Embed game window into community
Add following code to your Initialize() function in your game class, below the comment // game initialization code here
// game initialization code here
if (Window != null)
{
J2Play.GDKWrapper gdk = J2Play.GDKWrapper.GetInstance();
gdk.InsertGameIntoCommunity(Window.Handle, new System.Drawing.Size(800, 600));
}
J2Play.GDKWrapper.InsertGameIntoCommunity()
embed game window into j2play game community
Close community
When user do some operation leads to close, you should use following method to close community instead of close game window directly
J2Play.GDKWrapper.CloseCommunity()
Notification to community
When game state changes, you can use following method to notify community.
J2Play.GDKWrapper.ChangeCommunityState()
Notification for game
When community close, J2play GDK will trigger an event QuitApplication. Usually, if you handle all cleanup in game window close message handle, it is unnecessary to handle this event.
build and test
Build your project and test it.
Leaderboards
J2Play leaderboards list and store the best scores of a game. There are two sets of score APIs for diffirent score type
Type I: accumulative
This kind of score is accumulated through time. Like the money in a poker game. You can use following APIs to get previous score values you achieved and increase/decease them according game result.
J2Play.GDKWrapper.EasySetScore
Stores an array of score values for the specified user.
J2Play.GDKWrapper.EasyGetScore
Gets an array of score values for specific user.
Type II: highscore
This kind of score is achieve by every game played. Like score in a shooting game. You can use following API to report the score of current game.
J2Play.GDKWrapper.EasyHighScore
Report the score of current game.
Badges
Defining Badges
Use the J2Play Management Console to define the badge
Badges are defined as follows:
- badgeID - badgeID: number; // define the type of a badge
- badgeProperties - badgeProperties: ca.j2x.flash.util.Map; // define the properties of a badge
Every property in badgeProperties is a key / value pair (id=>value)
id: Number; // identification of badge argument value: String; // the value of specific badge argument
J2Play.GDKWrapper.TriggerBadgeEvent
Send a platform event to platform server, notifying that player got a badge.
Initializing the INI File
You should now have all of the J2Play dependencies within your program's executable directory. The final step in getting your game to talk to the J2Play playground involves modifying the j2play.ini file.
Within the j2play.ini file, you should have the following values:
[GameTemplate] templateName=default playernum= [SystemInfo] IP=production.j2play.net port=4501 GameID=0 NetworkID=@J2PLAY_NETWORK@ UserAgent="J2PlayGDK" HasServer = 0 [Facebook] facebook_userGUID=@J2PLAY_GUID@ facebook_screenname=@J2PLAY_SCREENNAME@ facebook_params=@FACEBOOK_PARAMS@
We only care about the bolded elements.
- playerNum: The number of players your game supports.
- GameID: The ID of your game (obtained from adding your game to admin).
- NetworkID: The network your game runs on (in this case we'll use Facebook).
- facebook_userGUID: Your facebook GUID. This can be found by logging into Facebook, accessing your profile page, and looking at the URL (example: http://www.facebook.com/home.php#/profile.php?id=<GUID>).
- facebook_screenname: Your desired facebook screen name.
- facebook_params: Example: ?userid=<GUID>&screenname=<screen name>&networkid=<networkid>&gameid=<gameid>&imageurl=<profile picture>
Challenges
BETA
contact developer@j2play.net before using this feature for technical support
You can make your game work with the challenge system according to this Challenge Toturial
Credits
BETA
contact developer@j2play.net before using this feature for technical support
Loyalty credits define a point and currency system in one. Users gain points from game achievements or purchase, and can spend them on other games or items.
