GamesChart Android API Implementation - IDE

From GamesChart

Jump to: navigation, search

Implement the GamesChart API using the IDE method by following 2 simple steps:

File:Android-placeholder.jpg

Contents

Step 1 - Including the jar file


The entire Games Chart API is contained in 1 small jar file. This needs to be included in your application. You can download the latest API jar file here. [insert hyperlink] There are a couple of standard ways to include external jar files. These are not GamesChart specific operations, so whichever method you’re most comfortable with is just fine.


Your Project > (Right Click) Import > File System > (Browse to) GamesChartAPI.jar

Your Project > (Right Click) Properties > Java Build Path > Libraries > Add Jar > (Browse to) GamesChartAPI.jar

File:Android-placeholder.jpg

Step 2 - AndroidManifest.xml


Locate your AndroidManifest.xml file

Find the following line, and make sure you set the android target sdk version to 8. This enables us to correctly determine the screen resolution of the device we're running on.

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />

Next add the required permissions. Below is the complete list of permissions that the GamesChart API requires, so add as many as you need.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

Finally, add the following line after your activity block:

<activity android:name="com.gcapi.GamesChart"></activity>

A complete AndroidManifext.xml should look something like this, once the GamesChart entries have been added:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.droidnova.android.games.vortex"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".Vortex"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.gcapi.GamesChart"></activity>
    </application>
</manifest>

File:Android-placeholder.jpg

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);

File:Android-placeholder.jpg

Additional Games Chart Functionality


If you’re happy with the way GamesChart looks and is working, great, you don’t need to do anything else. However, if you want to change the way GamesChart works for you, we’ve created some functions for you to use. These functions may be called at any point you like during your game flow.

Open / Close Charts
If you would like to control when the Charts are displayed in your game; at “Level Complete” or “Game Over” for example, you can simply use the open and close methods.

GamesChart.openCharts(); // forces the charts to be displayed

GamesChart.closeCharts(); // forces the charts to be closed again



Personal tools