Developer API


Flash Game Integration:

Play2Shop provides a gaming API for developers so they can easily integrate their games into the Play2Shop Gaming Platform (PGP).

When your game is run within the Play2Shop platform, it will run in an IFRAME with the parent window containing the Play2Shop JavaScript Game Library (see image to the right).

During the course of game-play, your game will send messages to the PGP system via JavaScript calls from within your game, as in:

parent.gameplay.msg( MESSAGE, OPTIONAL_DATA )

The messages that the PGP system is interested in are:

  1. Initial Startup. Let the system know when the user actually starts the game, usually when they click START from within your game.
  2. Game Play. As the user plays, let the system know every time they generate a score by sending the amount scored to the system.
  3. End of Game. Let the system know when the game ends.

To send a message from within your game to the Play2Shop JavaScript Game Library, the game should use the following format:

parent.gameplay.msg( mtype, data );

  where:

  mtype = (numeric) Message type, either JS object reference or corresponding numeric value.
  data  = (JSON object, or NULL) 

Specific messages include (JS object name and corresponding numeric value):

// standard messages
parent.gameplay.GAME_START         // 2
parent.gameplay.GAME_SCORE         // 16
parent.gameplay.GAME_END           // 512

// messages reserved for advanced integration
parent.gameplay.GAME_INIT          // 1
parent.gameplay.GAME_PULSE         // 4
parent.gameplay.GAME_MOVE          // 8
parent.gameplay.GAME_SCORE         // 16
parent.gameplay.GAME_GIVEUP        // 256

What Messages To Pass When:

Games should pass a GAME_START message as soon as the game begins, and likewise GAME_END when the game has completed. The GAME_END message MUST include a {score:x} data element, where “x” represents the final score.

During game play, the game sends ongoing scoring information (GAME_SCORE, {score:x}). Scoring data MUST include a “score” value, but can also include other elements as desired.

Example Messages:

// Sent when the user STARTS the game:
parent.gameplay.msg( parent.gameplay.GAME_START );

// Sent as the user generates scores:
// (in this case the user generated 100 points
parent.gameplay.msg( parent.gameplay.GAME_SCORE, { score : 100 } );

// Sent when the game ends, including the final score
// (in this case the final score was 5000
parent.gameplay.msg( parent.gameplay.GAME_END, { score : 5000 } );

And here's an example of sending the message from within your flash code:

getURL("javascript:parent.gameplay.msg( parent.gameplay.GAME_START )");

download the test harness


MESSAGE DOCUMENTATION:

Standard Messages

GAME_START: Called when the gameplay begins. value: 2 usage: parent.gameplay.msg( parent.gameplay.GAME_START ); // NOTE: THIS IS A REQUIRED MESSAGE GAME_SCORE: Called when scoring events occur in the game. If there are lots of scoring events within a relatively short period of time, they can be aggregated to minimize the number of calls to this message. value: 16 usage: parent.gameplay.msg( parent.gameplay.GAME_SCORE, {score:x} ); // NOTE: THIS IS A REQUIRED MESSAGE, CALLED EACH TIME THE USER GENERATES A SCORE GAME_END: Called when the game successfully ends. value: 512 usage: parent.gameplay.msg( parent.gameplay.GAME_END, {score:x} ); // NOTE: score is REQUIRED and represents the FINAL score of the game.

Advanced Integration Messages

GAME_INIT: Called when the game first initializes. value: 1 usage: parent.gameplay.msg( parent.gameplay.GAME_INIT ); GAME_PULSE: Optionally called periodically to notify the PGP system that the game is still playing when no other messages are actively being sent. value: 4 usage: parent.gameplay.msg( parent.gameplay.GAME_PULSE, {p1:x} ); GAME_MOVE: Optionally called when move events occur in the game. If there are lots of move events within a relatively short period of time, they can be aggregated or summarized to minimize the number of calls to this message. value: 8 usage: parent.gameplay.msg( parent.gameplay.GAME_MOVE, {r:7,c:12} ); GAME_GIVEUP: Called if the user ends the game without completing it. value: 256 usage: parent.gameplay.msg( parent.gameplay.GAME_GIVEUP );
about   |   advertise   |   faq   |   support   |   blog   |   news   |   social links   |   ambassadors   |   winner's circle
© Copyright 2012-2014 by Merchant Marketing Concepts, Inc. dba Play2Shop, All Rights Reserved