2. Agenda
Que es Game Center?
Características
Configuración / integración
Repaso features mas importantes
iOS 5
Ventajas / limitaciones
Temas mas avanzados
Para seguir leyendo
3. Que es Game Center?
Una iOS app
Un conjunto de
servicios
Un API
4. Que funcionalidad
provee?
Autenticación Matchmaking
Lista de Amigos Peer-to-peer
Leaderboards Voice chat
Achievements
5. Características de Game
Center
Es parte de GameKit (disponible desde iOS
3.0)
>= iOS 4.1, no compatible con iPhone 3g ni
iPod 1ra generación
Algunas cosas no se puede probar en el
simulador
Entornos: sandbox / producción
6. Características del API
Posts y requests
Estandar UI vs custom
Funciones asicrónicas
Blocks
Si un post falla es tu responsabilidad
Infomación cacheada
7. Manos a la obra!
1. Crear la app en iTunes Connect
2. Habilitar Game Center
3. Setear el Bundle ID en nuestra app
4. Agregar GameKit.framework
5. Import <GameKit/GameKit.h>
6. Opcional o no
8. Autenticación
Lo antes posible
playerID: único, el mismo en distintos dispositivos
Atributos propios
Tres escenarios:
Usuario ya logueado
Usuario no logueado,
pero ya registrado
Usuario no logueado,
sin registrar
10. Lista de amigos
Obtener una lista de playerIDs
Obtener una lista de GKPlayers
Incorporar servicios no soportados por GC:
Atributos propios
Enviar gifts
Enviar mensajes
Las amistades se crean desde Game Center app.
GKFriendRequestComposeViewController (iOS 4.2 )
11. Lista de amigos
Lista playerIDs
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer loadFriendsWithCompletionHandler:^(NSArray *identifiers, NSError *error) {
if (identifiers) {
// Array de player identifiers, puede ser info cacheada
}
if (error) {
}
}];
Lista GKPlayers
[GKPlayer loadPlayersForIdentifiers:identifiers WithCompletionHandler:^(NSArray *friends,
NSError *error) {
if (friends) {
// Array de GKPlayer
}
if (error) {
}
}];
12. Leaderboards
De todos los gustos y colores
Se configura desde iTunes
connect, muy simple (es un ABM)
Id, orden, tipo (entero, dinero,
decimal, tiempo)
Localizable (nombre, imagen,
sufijo, formato)
Máximo de 25
Default
Estandar UI o custom
14. Leaderboards - Listando
scores
GKLeaderboard *leaderboard = [[[GKLeaderboard alloc] initWithCategory:@”identifier”]
autorelease];
leaderboard.timeScope = GKLeaderboardTimeScopeWeek;
leaderboard.friendScope = GKLeaderboardPlayerScopeFriendsOnly;
leaderboard.range = NSMakeRange(1,25);
[leaderboard
loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
if (scores) {
// Array de GKScore, puede ser info cacheada
}
if (error) {
}
}];
15. Achievements
Se configura desde iTunes connect,
tambien muy simple
Id, oculto
Localizable (nombre, imagen, 2
descripciones)
Estandar UI o custom
Que podemos hacer?
Listar todos los achievements, Consultar
los ganados, reportar progreso, resetar
16. Achievements - Traer
todos
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
^(NSArray *descriptions, NSError *error) {
if (descriptions) {
// Array de GKAchievementDescriptions, info cacheada , trae
// ocultos!!
}
if (error) {
}
}];
18. Achievements -
Consultar los ganados
[GKAchievement loadAchievementsWithCompletionHandler:
^(NSArray *achievements, NSError *error) {
if (achievements) {
// Array de GKAchievements, puede ser info cacheada
}
if (error) {
}
}];
19. Matchmaking
Quiero arrancar una partida multiplayer!
Cantidad de jugadores (min/max)
Auto-match: Sobre jugadores que estan
esperando comenzar a jugar
Invitación:
Sobre jugadores epecificos, amigos
generalmente. Los cuales:
Pueden estar jungado la app
Pueden no estar jugando la app
No esta jungado ni tiene la app instalada
20. Matchmaking
Opciones para implementar matchmaking:
Estandar UI
Custom: custom UI o simplemente un boton
(solo para Auto-match)
Estan todos los jugadores, y ahora?:
Peer-to-peer (GKMatch)
Juego hosteado por nosotros (PlayerIDs)
22. Matchmaking - Crear un
match (Estandar UI)
- (void)matchmakerViewControllerWasCancelled:(GKMatchmakerViewController
*)viewController {
// Dismiss view controller
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController
didFailWithError:(NSError *)error {
// Dismiss view controller y mostrar error
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController
didFindMatch:(GKMatch *)match {
// Comenzar el juego usando GKMatch
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController
didFindPlayers:(NSArray *)playerIDs {
// Comenzar el juego usando el array de playerIDs
}
23. Matchmaking - Crear un
match (custom)
GKMatchRequest *matchRequest = [[[GKMatchRequest alloc] init] autorelease];
matchRequest.minPlayers = 2;
matchRequest.maxPlayers = 4;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:matchRequest
withCompletionHandler:^(GKMatch *match, NSError *error) {
if (!error) {
// Hacer algo con GKMatch
}
}];
24. GKMatch
Maneja la comunicación durante una partida
Recibe datos de otros jugadores (NSData)
Envía datos a otros jugadores (NSData)
Inicia el chat de voz
25. GKMatch
Enviar datos a los otros jugadores
NSData *data = ...;
NSError *error = nil
[match sendDataToAllPlayers:data withDataMode:GKMatchSendDataReliable
error:&error];
Desconectarme de un partido
[match disconnect];
26. GKMatch
GKMatchDelegate
- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString
*)playerID {
// Procesar informacion recibida
}
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:
(GKPlayerConnectionState)state {
// Procesar desconexión de un jugador
}
- (void)match:(GKMatch *)match connectionWithPlayerFailed:(NSString *)playerID
withError:(NSError *)error {
// Procesar error de conexión
}
- (void)match:(GKMatch *)match didFailWithError:(NSError *)error {
// Procesar error de conexión con todos los jugadores
}
28. Chequear si Game
Center esta presente
Puede no estar si:
< iOS 4.1
iPhone 3g, iPod 1ra generación
Para esos casos:
Weak reference al framework
Y el siguiente código:
29. Chequear si Game
Center esta presente
Class gameCenterPlayerClass = NSClassFromString(@"GKLocalPlayer");
if (gameCenterPlayerClass != nil) {
NSString *reqSysVer = @"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer
options:NSNumericSearch] != NSOrderedAscending) {
return YES;
}
}
return NO;
31. iOS 5: Que hay de
nuevo?
GKTurnBasedMatch
GKNotificationBanner
GKAchievement (show banner)
GKPlayer (Profile picture)
Mejoras en la app Game Center
32. Ventajas / Limitaciones
Ventajas
Mucha funcionalidad gratis
Facil de usar
Visibilidad
Limitaciones
Version iOS y dispositivos
Matchmaking y peer-to-peer solo usuarios GC
UI no es 100% customizable
33. Que no vimos
Manejar GKInvite
Multitasking: Algunos issues en iOS 4.1, resueltos
en iOS 4.2
Aggregate Leaderboards
Matchmaking avanzado: groups (level), attributes
(rol)
Hostear un juego
Voice chat con GKMatch
Otras funciones de GameKit: Peer-to-peer, In-Game
voice
34. Para seguir leyendo
Beginning iOS Game Center and Game Kit (Apress)
WWDC 2010 y 2011 videos: http://developer.apple.com/videos/wwdc/2010/
Game Kit Programming Guide: http://developer.apple.com/library/ios/
#documentation/NetworkingInternet/Conceptual/GameKit_Guide/
Introduction/Introduction.html
http://www.raywenderlich.com/tutorials
Proyectos GKTapper y GKTank