E: me@sabisin.com | T: +4915168651209

GameKit

GameKit is a native extension that allows the use of iOS GameKit framework. The extension allows your game to setup real time Game Center matches for up to 4 players, send and receive custom data between players, and enable voice chat during gameplay. It implements a subset of the iOS GameKit framework.

http://airextensions.net/shop/extensions/game-kit-by-vitapoly

Sample

var gamekit:GameKit = new GameKit();
 
// Authenticate the local player, but listen to the events first:
gamekit.addEventListener(GameKit.LOCAL_PLAYER_AUTHENTICATED_EVENT, function(e:Event):void {
    trace("LOCAL_PLAYER_AUTHENTICATED_EVENT");
});
 
gamekit.addEventListener(GameKit.LOCAL_PLAYER_NOT_AUTHENTICATED_EVENT, function(e:Event):void {
    trace("LOCAL_PLAYER_NOT_AUTHENTICATED_EVENT");
});
 
gamekit.authenticateLocalPlayer();
 
//Get info about local player after successful authentication:
var localPlayer:LocalPlayer = gamekit.getLocalPlayer();
trace(localPlayer.displayName);
 
for (var friend:Player in localPlayer.friends)
    trace("friend: " + friend.displayName);
 
//Show native Game Center interface:
gamekit.showGameCenter();
 
//Start a real time match, but listen to events first:
gamekit.addEventListener(GameKit.MATCH_MAKER_FAILED_EVENT, function(e:ErrorEvent):void {
    debug("MATCH_MAKER_FAILED_EVENT: " + e.errorID + ", " + e.text);
});
 
gamekit.addEventListener(GameKit.MATCH_MAKER_CANCELLED_EVENT, function(e:Event):void {
    debug("MATCH_MAKER_CANCELLED_EVENT");
});
 
gamekit.addEventListener(GameKit.MATCH_MAKER_FOUND_MATCH_EVENT, function(e:MatchFoundEvent):void {
    debug("MATCH_MAKER_FOUND_MATCH_EVENT: " + JSON.stringify(e));
 
    match = e.match; // save the match somewhere
    if (match.expectedPlayerCount == 0)
        startGame(); // start game if not expecting anymore players
});
 
// bring up native match making interface for a match with 2 to 4 players
gamekit.startRealTimeMatch(2, 4);
 
// Send data to other players during game:
var data:ByteArray = new ByteArray();
data.writeUTFBytes("hello");
 
// send a reliable packet to all players
match.sendDataToAll(data, true);
 
// send an unreliable packet to the match's first player
match.sendData(match.players[0], data, false);
 
// Receive data from other players:
match.addEventListener(RealTimeMatch.RECEIVED_DATA_EVENT, function(e:DataReceivedEvent):void {
    debug("RealTimeMatch.RECEIVED_DATA_EVENT from " + e.player.playerID + ": " + e.data.toString());
});
 
// Start a voice chat with other players:
var chat:VoiceChat = match.getVoiceChat("all");
 
// join the voice chat so the player can hear other players
chat.join();
 
// set talk to true so other players can hear this player
chat.talk = true;
 
// Disconnect and properly dispose the match:
match.disconnect();
match.dispose(); // releases the native match object

Leave a Reply