Home - TeachMeInc/MathGames-SDK GitHub Wiki


General Overview
MathGames Methods
Events
Using QuestionPanel

General Overview

In order to use the MathGames SDK, you must first add the MathGames SDK SWC file to your project. Once this is done, you can talk to the MathGames API through the com.mathgames.api.local.MathGames singleton.

At the start of your game, some time before your main menu, you must call MathGames.instance.connect(config) with some basic configuration information in order to connect to the API. If this either succeeds or fails, then the MathGames singleton will fire either a MathGamesEvent.CONNECTED or MathGamesEvent.ERROR event. If you receive a connected event then it's okay to proceed with the game, and display the main menu options.

Example:

MathGames.instance.addEventListener (MathGamesEvent.CONNECTED, showMainMenu);
MathGames.instance.connect ({
    "api_key": "123456789abcde",  // The API key for your game
    "pool_key": "COMPLETE"        // The default question pool to pull from
});

The MathGames API operates in discrete gameplay sessions. In order to start receiving questions from the API, you must start a session. Before you can start a session, however, you must allow the player to select a skill by prompting them with the Skill Select screen. This is done by calling MathGames.instance.selectSkill(). You'll know when the player is done with the skill select screen by receiving either a MathGamesEvent.SKILL_SELECTED or a MathGamesEvent.SKILL_SELECT_CANCELLED event. Typically you'll call selectSkill() when the player hits "Play" on the main menu, and then actually start the game once you receive the SKILL_SELECTED event. You can display the Skill Select screen at any time during the game, but typically you'll have a "Select a different skill" button on a menu presented between gameplay sessions.

Now that we've connected and the player has selected a skill, we can start a session to begin receiving questions. This is done by making a call to MathGames.instance.startSession(). This method accepts optional configuration options, the details of which are presented in the MathGames Methods wiki page. Once the session is ready to begin, a MathGamesEvent.SESSION_READY event will be fired, and immediately afterwards the first MathGamesEvent.QUESTION_READY event will fire.

A session with the MathGames API consists of receiving a question through an event listener for MathGamesEvent.QUESTION_READY, and then invoking the callback provided in the event object to signal the player's answer. The QUESTION_READY event itself places an object of type com.mathgames.api.local.Question in its data field. This object provides information about the question, possible answers, and a callback to invoke with the players' choice. Once this callback is invoked, a new QUESTION_READY event will be fired from the MathGames singleton. This will continue until you call MathGames.instance.endSession() to end the gameplay session. You would do this when the player has finished a level, for instance.

Example:

MathGames.instance.addEventListener (MathGamesEvent.SESSION_READY, onSessionReady);
MathGames.instance.addEventListener (MathGamesEvent.QUESTION_READY, onQuestionReady);
MathGames.instance.startSession ();

function onSessionReady (e:MathGamesEvent) :void {
    bringOnTheEnemies ();
}

var _currentQuestion :Question;

function onQuestionReady (e:MathGamesEvent) :void {
    _currentQuestion = e.data as Question;
    showQuestionToPlayer (_currentQuestion);
}

function onPlayerAnswer (selectedAnswerIndex:int) :void {
    _currentQuestion.doAnswer (selectedAnswerIndex);
}

The Question class provides BitmapData objects containing a question and four possible answers to it. It also has a field describing which answer is the correct one. You can render the questions and answers from the BitmapData however you like, or if you'd prefer to have the rendering handled automatically you can use the SDK's included QuestionPanel class. For a working example of using the QuestionPanel please see the example game.

The MathGames actionscript SDK contains some more methods for displaying player progress and supported skills. These are covered in detail in further sections. There are also additional events you can listen for to determine what the average time for the current set of questions are. Please see the rest of the documentation for the details on how to use these features.