Step 3 - Code Setup
NOTE: Games Chart is implemented as a Linear Layout, so you'll need to identify your app's main Frame Layout in your resource file.
If your game isn't contained within a Frame Layout, see the the "Additional Help" section at the bottom of this page.
Example :
FrameLayout mainFrameLayout = (FrameLayout)findViewById(R.id.mainframe);
We now have a handle to our main frame, so lets add the main Games Chart code block
Once in here we can begin the set-up procedure.
You should have something like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Add the following code block.
///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1: INITIALISE GAMES CHART SYSTEM
///////////////////////////////////////////////////////////////////////////////////////////////////////
String gameID = "bc055fe4f21c9617e6463b7c0ecc7101"; // given when you register your game
GamesChart.setup(this, gameID);
///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2: ADD THE GAMES CHART LAYOUT LAYER
///////////////////////////////////////////////////////////////////////////////////////////////////////
mainFrameLayout.addView(GamesChart.getLayout(this));
Next, GamesChart just needs to know that you're ready to start the loading process.
This process can take a few seconds to check for connections and load assets and data,
so we recommend doing it at a sensible time, perhaps when you show a splash page or
company logo during loading. If you forget to add this step, GamesChart will fire it up on the first
touch event it receives.
///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3: TELL GAMES CHART THAT OUT GAME IS READY
///////////////////////////////////////////////////////////////////////////////////////////////////////
GamesChart.gameStarted();
Ok, just one more line to handle events and we're done.
Locate your onTouch method and add the following line
///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 4: INFORM GAMES CHART OF EVENTS (with optional code for pausing your game)
///////////////////////////////////////////////////////////////////////////////////////////////////////
// OPTIONAL - check to see if GamesChart has been opened
if (GamesChart.openChart(event)) {
// pause your game here if required
}
// OPTIONAL - check to see if GamesChart has been closed
else if (GamesChart.closeChart(event)) {
// un-pause your game here if required
}
// MANDATORY - check all GamesChart events
GamesChart.checkEvents(event);
|