GamesChart Android API Implementation - Hand Rolled

From GamesChart

Jump to: navigation, search

Implement the GamesChart API using the IDE method by following 3 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]

[1]

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.

<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.

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.getBaseContext(), gameID);

///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2: SET UP THE GAMES CHART LAYOUT
///////////////////////////////////////////////////////////////////////////////////////////////////////
LinearLayout gc = GamesChart.getLayout(this); // get the GamesChart layout
        
///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3: ADD A LISTENER TO HANDLE EVENTS
///////////////////////////////////////////////////////////////////////////////////////////////////////
gc.setOnTouchListener(new OnTouchListener() { 
    // we do this here to enable us to launch an activity from our app
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction())
        {	
            case MotionEvent.ACTION_MOVE:
                GamesChart.touchMove(event.getX(), event.getY());
                break;
            case MotionEvent.ACTION_UP:
                if (GamesChart.touchRelease(event.getX(),event.getY()))
                    startActivity(GamesChart.getIntent(true));
                break;
            case MotionEvent.ACTION_DOWN:
                GamesChart.touchDown(event.getX(), event.getY());
                break;
        }
        return true;
    }
});

///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 4: ADD THE GAMES CHART LAYOUT LAYER
///////////////////////////////////////////////////////////////////////////////////////////////////////
mainFrameLayout.addView(gc); 


Ok, nearly done. We just need to let the GamesChart system know that we're ready to go, so we need to add the following

///////////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 5: TELL GAMES CHART THAT OUT GAME IS READY
///////////////////////////////////////////////////////////////////////////////////////////////////////
GamesChart.gameStarted(true); // start in a new thread
//GamesChart.gameStarted(false); // don't start a new thread

NOTE: Be careful where you do this. We recommend waiting until your game has loaded and is displaying something before telling the GamesChart system to start loading up it's assets. If you add it directly after STEP 4, you may experience some lag whilst loading your game.

Ok, that's all the code we need.

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