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