GamesChart Android GamesChart API Implementation - IDE

[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 from the developer site. 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 [Step 2 - Adding the code] 1) Setup Your application will have a main View type, most likely SurfaceView.. this is where you will initialise the Games Chart system and check for any relevant events. The setup method simply needs a reference to the view’s context and a String containing your unique gameID. public static void setup(Context context, String gameID) In this class, wherever you initialise your game, add the following line of code* // GAMESCHART CODE START: SETUP: setup GamesChart.setup(this.getContext, gameID); // GAMESCHART CODE END: SETUP: setup This will set up the Games Chart system for use.  // GAMESCHART CODE START: SETUP: setup GamesChart.setup(this.getBaseContext,gameID); // GAMESCHART CODE END: SETUP: setup If your class already has a context explicitly defined, you can pass that instead, like this // GAMESCHART CODE START: SETUP: setup GamesChart.setup(mContext,gameID); // GAMESCHART CODE END: SETUP: setup 2) Draw The actual rendering of the Games Chart system is no different from your in-game graphics system. It uses a Canvas to draw itself on top of your game, so we need a reference to your game's canvas. The draw method just needs a Canvas to draw to  public static void draw(Canvas canvas) Find your game's main draw method and add the following code at the end of your drawing code.  // GAMESCHART CODE START: DRAW: draw GamesChart.draw(canvas); // GAMESCHART CODE END: DRAW: draw This will show the GamesChart show/hide tab in the default position, which is the top right hand side of the screen. If you wish to change this position, simply add x and y parameters. // GAMESCHART CODE START: DRAW: draw GamesChart.draw(canvas, x, y); // GAMESCHART CODE END: DRAW: draw This will show the GamesChart show/hide tab at the x and y position you pass  3) Check for Events Search your code for "onTouchEvent"* You should have something like this:* if (event.getAction == MotionEvent.ACTION_DOWN) { You just need to add one small block here: // GAMESCHART CODE START: CHECK EVENTS: onTouchEvent if (GamesChart.checkClick((int)event.getX, (int)event.getY)) { this.getContext.startActivity(GamesChart.getIntent(true)); } // GAMESCHART CODE END: CHECK EVENTS: onTouchEvent
 * Alternatives: If you have trouble with getContext, try using getBaseContext in it’s place, so your code will look lke this

This checks with the GameChart API to see if the tab has been clicked. If it has, it will check to see which part of the chart has been clicked, then carry out any required actions.

That’s it !! You’re done. Easy wasn’t it?

@Override public boolean onTouchEvent(MotionEvent event) {
 * Don’t have an onTouchEvent method? You do, but you don’t have MotionEvent.ACTION_DOWN events defined? No problem. The whole onTouchEvent section is listed below, so you can see clearly which parts you need to add.

if (event.getAction == MotionEvent.ACTION_DOWN) {

// START GAMES CHART EVENT: onTouchEvent if (GamesChart.checkClick((int)event.getX, (int)event.getY)) { this.getContext.startActivity(GamesChart.getIntent(true)); }         // END GAMES CHART EVENT: onTouchEvent }  return true; }

TIP: You may want to make sure that you call your game’s pause method just before you call startActivity. 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’d like to control when GamesChart is 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