SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
Multiplayer Games Magnus Jahnensgd-ws13
Multiplayer Games
with iOS
Seminar Games Development (WS13/14)
04.10.2013
Session 14
“Tell me and I will forget.
Show me and I will remember.
Involve me and I will understand.
Step back and I will act.”
1
Multiplayer Games Magnus Jahnensgd-ws13
Multiplayer Games with iOS
• Introduction
• Game Center
• MultipeerConnectivity
• Motivation
• Overview
• Realtime multiplayer (SpaceInvaders)
• With Game Center
• With MultipeerConnectivity
• Summary and tips
• Helpful links
• References
2
Multiplayer Games Magnus Jahnensgd-ws13
Introduction - Game Center
• Social Gaming Network developed by Apple
• Makes third party frameworks like OpenFeint obsolete
• Available in iOS 4.1 (2010) and OS X 10.8 (2012)
• Features:
• Leaderboards
• Achievements
• Challenges
3
Multiplayer Games Magnus Jahnensgd-ws13
Introduction - Game Center
4
Real Time Multiplayer
Doodle Jump Real Racing 3
Multiplayer Games Magnus Jahnensgd-ws13
Introduction - Game Center
5
Turn Based Multiplayer
CarcassonneWord Rally
Multiplayer Games Magnus Jahnensgd-ws13
Introduction - MultipeerConnectivity
• Framework to communicate between nearby devices
• Introduced in iOS 7 (not available on OS X)
• Replaces facilities to communicate with nearby devices
in GameKit Framework
• Features:
• Discovering and exchanging data between nearby devices
• Message, stream based data and resources such as files
6
Multiplayer Games Magnus Jahnensgd-ws13
Motivation
• Multiplayer games obviously are fun
• Can fascinate players even if the storyline is over
• Real interaction with other players and social
interaction are more appreciated than just with a
computer
• Both Frameworks have a really easy to use API and
a high level user interface
7
Multiplayer Games Magnus Jahnensgd-ws13
Network layer
• Layer 4 or Transport layer (OSI model)
8
TCP
• Connection oriented
• Stream based data
• Reliable
• Higher overhead than UDP
• Slower transmission speed than
UDP
UDP
• Connection less
• Package based data
• Unreliable
• Very low overhead
• Very high transmission speed
Multiplayer Games Magnus Jahnensgd-ws13
Network Guidelines
• Handle network disruptions
• Send packages at lowest frequency
• Network updates are not needed 30 times per second!
• Use smallest package size possible
• Send data only to the players who need it
9
Multiplayer Games Magnus Jahnensgd-ws13
What we will do now
• Adapt the SpaceInvaders Tutorial
• To a real time multiplayer game
• Supporting two players
10
Player One
Player Two
Multiplayer Games Magnus Jahnensgd-ws13
Overview
11
1 1
MultiPeerCommunicationGameCenterCommunication
CommunicationStrategy
«protocol»
+findMatch()
+sendData(NSData *)
+disconnect()
MultiPlayerHelper
+sharedInstance()
+findMatch()
Multiplayer Games Magnus Jahnensgd-ws13
Before we start
• Debug builds use the Game Center Sandbox
environment
• Use eduroam network
• Use 3.5 inch iPhone Simulator (32bit)
• TODOs are marked with warnings
12
Multiplayer Games Magnus Jahnensgd-ws13
Game Center
13
Multiplayer Games Magnus Jahnensgd-ws13
Important classes
14
GKMatchRequest GKMatchmaker
ViewController
GKMatch
Multiplayer Games Magnus Jahnensgd-ws13
Overview
15
1
matchmakerDelegate
1 1
1
GKMatch
+sendData(NSData)
+disconnect()
GameCenterCommunication
+findMatch()
GKMatchRequest
+maxPlayers
+minPlayers
GKMatchMakerViewController
+initWithMatchRequest(GKMatchRequest)
Multiplayer Games Magnus Jahnensgd-ws13
Finding players
16
Multiplayer Games Magnus Jahnensgd-ws13
GKMatchmakerViewController
17
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 1
• Init a GKMatchRequest and set
the properties minPlayers and
maxPlayers
• Init a
GKMatchmakerViewController
using initWithMatchRequest
• Set the matchmakerDelegate
property to self
• Present the ViewController via
[Helper presentViewController:]
• Time: 7 minutes
18
GKMatchRequest
GKMatchmaker
ViewController
Multiplayer Games Magnus Jahnensgd-ws13
Solution: TODO 1
19
- (void)findMatch {
NSLog(@"Searching a match ...");
#warning TODO 1a initialize a GKMatchRequest and set the maxPlayers and minPlayers
properties
GKMatchRequest *matchRequest = [[GKMatchRequest alloc] init];
matchRequest.maxPlayers = 2;
matchRequest.minPlayers = 2;
#warning TODO 1b present the ViewController
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]
initWithMatchRequest:matchRequest];
mmvc.matchmakerDelegate = self;
[Helper presentViewController:mmvc];
}
GameCenterCommunication.m
Multiplayer Games Magnus Jahnensgd-ws13
GKMatchMakerViewControllerDelegate
20
#pragma mark GKMatchmakerViewControllerDelegate
- (void)matchmakerViewControllerWasCancelled:(GKMatchmakerViewController *)viewController {
NSLog(@"matchmaking cancelled");
[Helper dismissViewController];
[self.delegate communicationStrategyDidCancelMatch];
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController
didFailWithError:(NSError *)error {
NSLog(@"Error finding match: %@", error);
[Helper dismissViewController];
[self.delegate communicationStrategyDidEndMatch];
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:
(GKMatch *)match {
NSLog(@"found match!");
[Helper dismissViewController];
self.currentMatch = match;
match.delegate = self;
[self lookupPlayers];
}
GameCenterCommunication.m
Multiplayer Games Magnus Jahnensgd-ws13
Running the game
• You should see the ViewController
• When you click cancel or play, you should see the
appropriate Messages in the console output
• You will not be able to play though!
21
2013-09-23 16:06:13.240 SpaceInvadersTutorial[1101:a0b] Searching a match ...
2013-09-23 16:06:15.768 SpaceInvadersTutorial[1101:a0b] matchmaking cancelled
2013-09-23 16:06:15.991 SpaceInvadersTutorial[1101:a0b] User clicked cancel!
2013-09-23 17:42:41.353 SpaceInvadersTutorial[4601:a0b] Searching a match ...
2013-09-23 17:43:29.832 SpaceInvadersTutorial[4601:a0b] found match!
2013-09-23 17:43:29.860 SpaceInvadersTutorial[4601:a0b] Looking up 1 players
Multiplayer Games Magnus Jahnensgd-ws13
22
Network
Communication
Multiplayer Games Magnus Jahnensgd-ws13
Sending data
• Send data by calling sendData from class GKMatch
• Takes NSData which is just an array of bytes
• Data can be sent reliable or unreliable
• Remember the networking guidelines mentioned
before
• Small package size
• Lowest frequency
• Network topologies
• etc.
23
Multiplayer Games Magnus Jahnensgd-ws13
Sending Reliable (TCP)
• Guaranteed delivery
• No out of order packets
➡ Easy to use
• But may be slower!
➡ For infrequent messages which need to reach their
destination!
24
Multiplayer Games Magnus Jahnensgd-ws13
Sending Unreliable (UDP)
• Faster than reliable
• No guaranteed delivery
• Maybe out of order packets
➡ For real time updates (e.g. position updates)
25
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 2
26
• Implement the method sendEnemySpawned in
MultiPlayerHelper.m
• Use [self getRelativePosition:] to get a relative position to
screen
• Init a EnemySpawnedMessage and send it via
[self sendMessage:]
• Time: 5 minutes
@interface EnemySpawnedMessage : Message
...
- (id)initWithEnemyIndex:(NSUInteger)index atPosition:(CGPoint)position;
...
@end
Hint:
Multiplayer Games Magnus Jahnensgd-ws13
Solution: TODO 2
27
MultiPlayerHelper.m
- (void)sendEnemySpawned:(int)enemyIndex atPosition:(CGPoint)position {
#warning TODO 2 send when an enemy/alien spawned
CGPoint relativePosition = [self getRelativePosition:position];
EnemySpawnedMessage *message = [[EnemySpawnedMessage alloc]
initWithEnemyIndex:enemyIndex atPosition:relativePosition];
[self sendMessage:message];
}
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 3
28
• Implement the method parseEnemySpawned in MultiPlayerHelper.m
• Use [self getAbsolutePosition:] to get an absolute position to
screen
• Use the property self.networkDelegate to notify the Game Scene
• Time: 5 minutes
@interface EnemySpawnedMessage : Message
@property NSUInteger enemyIndex;
@property CGPoint position;
...
@end
@protocol NetworkDelegate
...
- (void)enemySpawned:(int)enemyIndex atPosition:
(CGPoint)position;
...
@end
Hints:
Multiplayer Games Magnus Jahnensgd-ws13
Solution: TODO 3
29
MultiPlayerHelper.m
- (void)parseEnemySpawnedMessage:(EnemySpawnedMessage *)message {
#warning TODO 3 parse the enemy message
CGPoint absolutePosition = [self getAbsolutePosition:message.position];
[self.networkDelegate enemySpawned:message.enemyIndex
atPosition:absolutePosition];
}
Multiplayer Games Magnus Jahnensgd-ws13
Whats missing?
• Player Position updates
➡ Good example where unreliable packages are useful
30
Multiplayer Games Magnus Jahnensgd-ws13
How to deal with the Problems
• Lost packages
➡ Just ignore them
• Out of order packages
➡ Just use the most recent received information
• These solutions apply for most scenarios!
31
Multiplayer Games Magnus Jahnensgd-ws13
Problem: Out of Order Packages
• Include a message counter in the position update
message
• Compare it with the message count we expect next
➡ Bigger or equal → Valid
➡ Otherwise we just drop the package
32
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 4
33
MultiPlayerHelper.m
- (void)sendPlayerPosition:(CGPoint)position {
#warning TODO 4 send the player position unreliable
self.outgoingCounter++;
CGPoint relativePosition = [self getRelativePosition:position];
PlayerPositionUpdateMessage *message = [[PlayerPositionUpdateMessage alloc]
initWithPosition:relativePosition andMessageCount:self.outgoingCounter];
[self sendMessageUnreliable:message];
}
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 5
34
MultiPlayerHelper.m
- (void)parsePlayerPositionUpdateMessage:(PlayerPositionUpdateMessage *)message {
#warning TODO 5 parse the position update message
// sorry, but out of order -> just ignore
if(self.incomingCounter >= message.messageCount) {
NSLog(@"received out of order position update!");
return;
}
CGPoint absolutePosition = [self getAbsolutePosition:message.playerPosition];
self.incomingCounter = message.messageCount;
[self.networkDelegate playerPositionChanged:absolutePosition];
}
Multiplayer Games Magnus Jahnensgd-ws13
35
Play!
Multiplayer Games Magnus Jahnensgd-ws13
36
MultipeerConnectivity
Multiplayer Games Magnus Jahnensgd-ws13
Overview
37
Session Session
Session
Multiplayer Games Magnus Jahnensgd-ws13
Important classes
38
MCAdvertiserAssistant
MCBrowserView
Controller
MCSessionMCPeerID
Multiplayer Games Magnus Jahnensgd-ws13
Overview
39
1
1
1
delegate
1 1
delegate
1
1
MultiPeerCommunication
+findMatch()
MCBrowserViewController
+serviceType: NSString*
+maximumNumberOfPeers
+minimumNumberOfPeers
MCAdvertiserAssistant
+serviceType: NSString*
+start()
+stop()
MCSession
+sendData(NSData *)
MCPeerID
+playerName
Multiplayer Games Magnus Jahnensgd-ws13
Bonjour
• Apples implementation of Zeroconf networking
• Used to find available services in a network using
multicast
‣ Identified via the service type
• Used for example in iTunes or to easily find network
printers
40
Multiplayer Games Magnus Jahnensgd-ws13
Presenting the UI
41
Passive
via Advertiser
Active
via ViewController
Multiplayer Games Magnus Jahnensgd-ws13
Change the Strategy!
42
#warning TODO change the strategy
[MultiPlayerHelper sharedInstance].communicationStrategy = [[GameCenterCommunication
alloc] init];
ViewController.m
Change
To
[MultiPlayerHelper sharedInstance].communicationStrategy = [[MultiPeerCommunication alloc]
initWithPlayerName:@"Your Name"];
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 6
• Init a MCPeerID with self.playerName
• Init a MCSession (property) with the peer ID
• Do not forget to set the delegate!
• Init a MCAdvertiserAssistant (property) with
service type „space“, „nil“ as discovery Info
and the session
• Then start the Advertiser
• Time: 7 minutes
43
MCPeerID
MCSession
MCAdvertiser
Assistant
Multiplayer Games Magnus Jahnensgd-ws13
Solution: TODO 6
44
- (void)setupSession {
#warning TODO 6 setup up the MultipeerConnectivity Session
MCPeerID *peer = [[MCPeerID alloc] initWithDisplayName:self.playerName];
self.session = [[MCSession alloc] initWithPeer:peer];
self.session.delegate = self;
self.advertiserAssistant = [[MCAdvertiserAssistant alloc]
initWithServiceType:@"space" discoveryInfo:nil session:self.session];
[self.advertiserAssistant start];
}
MultiPeerCommunication.m
Multiplayer Games Magnus Jahnensgd-ws13
Exercise: TODO 7
• First stop the Advertiser!
• Init a MCBrowserViewController with
Service Type „space“ and the
property session
• Do not forget to set the delegate and
maximum and minimum number of
peers
• Present the ViewController via
[Helper presentViewController:]
• Time: 7 minutes
45
MCPeerID
MCSession
MCBrowserView
Controller
Multiplayer Games Magnus Jahnensgd-ws13
Solution: TODO 7
46
- (void)findMatch {
#warning TODO 7 find a match/other peers using MultipeerConnectivity
[self.advertiserAssistant stop];
MCBrowserViewController *viewController = [[MCBrowserViewController alloc]
initWithServiceType:@"space" session:self.session];
viewController.delegate = self;
viewController.maximumNumberOfPeers = 2;
viewController.minimumNumberOfPeers = 2;
[Helper presentViewController:viewController];
}
MultiPeerCommunication.m
Multiplayer Games Magnus Jahnensgd-ws13
47
Play!
Multiplayer Games Magnus Jahnensgd-ws13
Summary
• You are now able to build a multiplayer game!
Congratulations!
• You know why Game Center and
MultipeerConnectivity are useful
• You know how you can find matches (other players)
with the standard View Controllers
• You know how to send and receive data over a
GKMatch or MCSession
• You know where you should pay attention at when
designing a multiplayer real time game
48
Multiplayer Games Magnus Jahnensgd-ws13
‣ Let the user decide
49
Game Center
• Server infrastructure supplied
by Apple
• Wide community
• Available on iOS and OS X
• More features available like
leaderboards or voice chat
• Dependent on Apple Servers
• No nearby players
MultipeerConnectivity
• No server needed
• Different communication Methods
(Bluetooth and Wifi)
• Seems to work better and faster
• Only nearby devices
• Available only on iOS
• Not optimized for gaming
Multiplayer Games Magnus Jahnensgd-ws13
Some tips
• Use my strategy pattern
• Enable Game Center/MultipeerConnectivity in the
Xcode project
• Register your app Bundle ID in iTunes Connect
• Check if the sandbox is online
• https://sandbox.itunes.apple.com/verifyReceipt
50
Multiplayer Games Magnus Jahnensgd-ws13
Helpful links
• Official Apple Game Center Guide
• https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/
GameKit_Guide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008304-CH1-
SW1
• How to Make a simple multiplayer game by Ray Wenderlich
• http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-
game-center-tutorial-part-12
• Nearby Networking with MultipeerConnectivity (Video)
• https://developer.apple.com/wwdc/videos/index.php?id=708
• About Multipeer Connectivity by Apple
• https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/
Reference/MultipeerConnectivityFramework/Introduction/Introduction.html
• Snap (card game by Ray Wenderlich)
• GameKit API deprecated, but good example how to exchange packages!
• http://www.raywenderlich.com/12735
51
Multiplayer Games Magnus Jahnensgd-ws13
Thank you!
Questions?
Do not hesitate to ask!
52
Multiplayer Games Magnus Jahnensgd-ws13
References
• https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Introduction/Introduction.html#//
apple_ref/doc/uid/TP40008304-CH1-SW1
• https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Matchmaking/Matchmaking.html#//
apple_ref/doc/uid/TP40008304-CH9-SW1
• https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework
• http://www.raywenderlich.com/12735
• http://iphonedevsdk.com/forum/iphone-sdk-development/96012-is-the-sandbox-down-i-keep-getting-http-unavailable.html
• http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12
• http://devstreaming.apple.com/videos/wwdc/2013/708xbx3x7xusbzidl0j3acxest/708/708.pdf?dl=1
• https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/Introduction/
Introduction.html
• https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/_index.html#//
apple_ref/doc/uid/TP40013328
• http://en.wikipedia.org/wiki/Bonjour_(software)
• http://en.wikipedia.org/wiki/OSI_model
• http://en.wikipedia.org/wiki/User_Datagram_Protocol
• http://en.wikipedia.org/wiki/Transmission_Control_Protocol
• http://en.wikipedia.org/wiki/Game_Center
53
Multiplayer Games Magnus Jahnensgd-ws13
Images
• Slide 3: Game Center Icon
• http://www.icreatemagazine.com/wp-content/uploads/2013/08/Game-Center2.png
• Slide 4 + 5: Example Applications
• http://1.bp.blogspot.com/-VN8uai_77pg/TZTNonsIzmI/AAAAAAAAAxY/qdVvIjwUNGA/s1600/Doodle%2BJump%2BMultiplayer.jpg
• https://itunes.apple.com/de/app/real-racing-3/id556164350?mt=8
• https://itunes.apple.com/us/app/word-rally/id447075138?mt=8
• https://itunes.apple.com/de/app/carcassonne/id375295479?mt=8
• Slide 6 + 37: MultipeerConnectivity
• http://devstreaming.apple.com/videos/wwdc/2013/708xbx3x7xusbzidl0j3acxest/708/708.pdf?dl=1
• Slide 10: Network topologies:
• https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Art/
network_topologies_2x.png
• Slide 40: Bonjour Icon
• https://devimages.apple.com.edgekey.net/bonjour/images/bonjour-hero.png
• Slide 52: MultipeerConnectivity
• http://www.theonliner.de/wp-content/uploads/2013/07/multipeer_004_220-e1373416225609.jpg
• Plus and minus signs:
• http://mountainss.files.wordpress.com/2012/12/plus-sign.png?w=256
• http://www.omgomfg.com/file/pic/photo/2012/09/rebelius-minus-sign.png
• All other images were made by myself
54

Contenu connexe

Tendances

Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA Game
Sohil Gupta
 
Pew pew game design document
Pew pew game design documentPew pew game design document
Pew pew game design document
ARshut Syabrin
 
7 gate game design document
7 gate game design document 7 gate game design document
7 gate game design document
ARshut Syabrin
 
Fungsi run
Fungsi runFungsi run
Fungsi run
amcied
 
Analog game gdd_revised
Analog game gdd_revisedAnalog game gdd_revised
Analog game gdd_revised
jowyn
 
Pew pew game design document
Pew pew game design documentPew pew game design document
Pew pew game design document
ARshut Syabrin
 
11thDimensionStudios_GDD_Final_0915
11thDimensionStudios_GDD_Final_091511thDimensionStudios_GDD_Final_0915
11thDimensionStudios_GDD_Final_0915
Blake Taylor
 

Tendances (20)

Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA Game
 
What Would Blizzard Do
What Would Blizzard DoWhat Would Blizzard Do
What Would Blizzard Do
 
Pew pew game design document
Pew pew game design documentPew pew game design document
Pew pew game design document
 
Production Log - Cosmic Constructor
Production Log - Cosmic ConstructorProduction Log - Cosmic Constructor
Production Log - Cosmic Constructor
 
Task 2 research
Task 2 researchTask 2 research
Task 2 research
 
Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014
 
Game design document
Game design document Game design document
Game design document
 
Academy PRO: Unity 3D. Environment
Academy PRO: Unity 3D. EnvironmentAcademy PRO: Unity 3D. Environment
Academy PRO: Unity 3D. Environment
 
7 gate game design document
7 gate game design document 7 gate game design document
7 gate game design document
 
Fungsi run
Fungsi runFungsi run
Fungsi run
 
2dworkflow complete
2dworkflow complete2dworkflow complete
2dworkflow complete
 
Analog game gdd_revised
Analog game gdd_revisedAnalog game gdd_revised
Analog game gdd_revised
 
unity basics
unity basicsunity basics
unity basics
 
Task 3.2 my computer game concept in detail presentation [my name] - 2017
Task 3.2   my computer game concept in detail presentation [my name] - 2017Task 3.2   my computer game concept in detail presentation [my name] - 2017
Task 3.2 my computer game concept in detail presentation [my name] - 2017
 
Lock and Key Design Document Draft Two
Lock and Key Design Document Draft Two Lock and Key Design Document Draft Two
Lock and Key Design Document Draft Two
 
Best 5 Fantasy MMORPG Games You Love to Play
Best 5 Fantasy MMORPG Games You Love to PlayBest 5 Fantasy MMORPG Games You Love to Play
Best 5 Fantasy MMORPG Games You Love to Play
 
Pew pew game design document
Pew pew game design documentPew pew game design document
Pew pew game design document
 
11thDimensionStudios_GDD_Final_0915
11thDimensionStudios_GDD_Final_091511thDimensionStudios_GDD_Final_0915
11thDimensionStudios_GDD_Final_0915
 
CreateJS
CreateJSCreateJS
CreateJS
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 

Similaire à Multiplayer games on iOS

Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking Game
Tanmay Krishna
 

Similaire à Multiplayer games on iOS (20)

Programming Language Final PPT
Programming Language Final PPTProgramming Language Final PPT
Programming Language Final PPT
 
Android game development
Android game developmentAndroid game development
Android game development
 
go-man API
go-man APIgo-man API
go-man API
 
Forest assassin 2 d platformer game
Forest assassin 2 d platformer gameForest assassin 2 d platformer game
Forest assassin 2 d platformer game
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking Game
 
Can a Paper-Based Sketching Interface Improve the Gamer Experience in Strateg...
Can a Paper-Based Sketching Interface Improve the Gamer Experience in Strateg...Can a Paper-Based Sketching Interface Improve the Gamer Experience in Strateg...
Can a Paper-Based Sketching Interface Improve the Gamer Experience in Strateg...
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 
Cross platform game development
Cross platform game developmentCross platform game development
Cross platform game development
 
Ancient world online
Ancient world online Ancient world online
Ancient world online
 
Java term project final report
Java term project final reportJava term project final report
Java term project final report
 
Capstone Project Final Presentation
Capstone Project Final PresentationCapstone Project Final Presentation
Capstone Project Final Presentation
 
Unit 20 - Game Platforms
Unit 20 - Game PlatformsUnit 20 - Game Platforms
Unit 20 - Game Platforms
 
Unit 20 - Game Platforms
Unit 20 - Game PlatformsUnit 20 - Game Platforms
Unit 20 - Game Platforms
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
 
Creating 3D games and applications using Castle Game Engine
Creating 3D games and applications using Castle Game EngineCreating 3D games and applications using Castle Game Engine
Creating 3D games and applications using Castle Game Engine
 
Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)
 
About Cocos2djs
About Cocos2djsAbout Cocos2djs
About Cocos2djs
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with Canvas
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNub
 

Dernier

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Multiplayer games on iOS

  • 1. Multiplayer Games Magnus Jahnensgd-ws13 Multiplayer Games with iOS Seminar Games Development (WS13/14) 04.10.2013 Session 14 “Tell me and I will forget. Show me and I will remember. Involve me and I will understand. Step back and I will act.” 1
  • 2. Multiplayer Games Magnus Jahnensgd-ws13 Multiplayer Games with iOS • Introduction • Game Center • MultipeerConnectivity • Motivation • Overview • Realtime multiplayer (SpaceInvaders) • With Game Center • With MultipeerConnectivity • Summary and tips • Helpful links • References 2
  • 3. Multiplayer Games Magnus Jahnensgd-ws13 Introduction - Game Center • Social Gaming Network developed by Apple • Makes third party frameworks like OpenFeint obsolete • Available in iOS 4.1 (2010) and OS X 10.8 (2012) • Features: • Leaderboards • Achievements • Challenges 3
  • 4. Multiplayer Games Magnus Jahnensgd-ws13 Introduction - Game Center 4 Real Time Multiplayer Doodle Jump Real Racing 3
  • 5. Multiplayer Games Magnus Jahnensgd-ws13 Introduction - Game Center 5 Turn Based Multiplayer CarcassonneWord Rally
  • 6. Multiplayer Games Magnus Jahnensgd-ws13 Introduction - MultipeerConnectivity • Framework to communicate between nearby devices • Introduced in iOS 7 (not available on OS X) • Replaces facilities to communicate with nearby devices in GameKit Framework • Features: • Discovering and exchanging data between nearby devices • Message, stream based data and resources such as files 6
  • 7. Multiplayer Games Magnus Jahnensgd-ws13 Motivation • Multiplayer games obviously are fun • Can fascinate players even if the storyline is over • Real interaction with other players and social interaction are more appreciated than just with a computer • Both Frameworks have a really easy to use API and a high level user interface 7
  • 8. Multiplayer Games Magnus Jahnensgd-ws13 Network layer • Layer 4 or Transport layer (OSI model) 8 TCP • Connection oriented • Stream based data • Reliable • Higher overhead than UDP • Slower transmission speed than UDP UDP • Connection less • Package based data • Unreliable • Very low overhead • Very high transmission speed
  • 9. Multiplayer Games Magnus Jahnensgd-ws13 Network Guidelines • Handle network disruptions • Send packages at lowest frequency • Network updates are not needed 30 times per second! • Use smallest package size possible • Send data only to the players who need it 9
  • 10. Multiplayer Games Magnus Jahnensgd-ws13 What we will do now • Adapt the SpaceInvaders Tutorial • To a real time multiplayer game • Supporting two players 10 Player One Player Two
  • 11. Multiplayer Games Magnus Jahnensgd-ws13 Overview 11 1 1 MultiPeerCommunicationGameCenterCommunication CommunicationStrategy «protocol» +findMatch() +sendData(NSData *) +disconnect() MultiPlayerHelper +sharedInstance() +findMatch()
  • 12. Multiplayer Games Magnus Jahnensgd-ws13 Before we start • Debug builds use the Game Center Sandbox environment • Use eduroam network • Use 3.5 inch iPhone Simulator (32bit) • TODOs are marked with warnings 12
  • 13. Multiplayer Games Magnus Jahnensgd-ws13 Game Center 13
  • 14. Multiplayer Games Magnus Jahnensgd-ws13 Important classes 14 GKMatchRequest GKMatchmaker ViewController GKMatch
  • 15. Multiplayer Games Magnus Jahnensgd-ws13 Overview 15 1 matchmakerDelegate 1 1 1 GKMatch +sendData(NSData) +disconnect() GameCenterCommunication +findMatch() GKMatchRequest +maxPlayers +minPlayers GKMatchMakerViewController +initWithMatchRequest(GKMatchRequest)
  • 16. Multiplayer Games Magnus Jahnensgd-ws13 Finding players 16
  • 17. Multiplayer Games Magnus Jahnensgd-ws13 GKMatchmakerViewController 17
  • 18. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 1 • Init a GKMatchRequest and set the properties minPlayers and maxPlayers • Init a GKMatchmakerViewController using initWithMatchRequest • Set the matchmakerDelegate property to self • Present the ViewController via [Helper presentViewController:] • Time: 7 minutes 18 GKMatchRequest GKMatchmaker ViewController
  • 19. Multiplayer Games Magnus Jahnensgd-ws13 Solution: TODO 1 19 - (void)findMatch { NSLog(@"Searching a match ..."); #warning TODO 1a initialize a GKMatchRequest and set the maxPlayers and minPlayers properties GKMatchRequest *matchRequest = [[GKMatchRequest alloc] init]; matchRequest.maxPlayers = 2; matchRequest.minPlayers = 2; #warning TODO 1b present the ViewController GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:matchRequest]; mmvc.matchmakerDelegate = self; [Helper presentViewController:mmvc]; } GameCenterCommunication.m
  • 20. Multiplayer Games Magnus Jahnensgd-ws13 GKMatchMakerViewControllerDelegate 20 #pragma mark GKMatchmakerViewControllerDelegate - (void)matchmakerViewControllerWasCancelled:(GKMatchmakerViewController *)viewController { NSLog(@"matchmaking cancelled"); [Helper dismissViewController]; [self.delegate communicationStrategyDidCancelMatch]; } - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFailWithError:(NSError *)error { NSLog(@"Error finding match: %@", error); [Helper dismissViewController]; [self.delegate communicationStrategyDidEndMatch]; } - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch: (GKMatch *)match { NSLog(@"found match!"); [Helper dismissViewController]; self.currentMatch = match; match.delegate = self; [self lookupPlayers]; } GameCenterCommunication.m
  • 21. Multiplayer Games Magnus Jahnensgd-ws13 Running the game • You should see the ViewController • When you click cancel or play, you should see the appropriate Messages in the console output • You will not be able to play though! 21 2013-09-23 16:06:13.240 SpaceInvadersTutorial[1101:a0b] Searching a match ... 2013-09-23 16:06:15.768 SpaceInvadersTutorial[1101:a0b] matchmaking cancelled 2013-09-23 16:06:15.991 SpaceInvadersTutorial[1101:a0b] User clicked cancel! 2013-09-23 17:42:41.353 SpaceInvadersTutorial[4601:a0b] Searching a match ... 2013-09-23 17:43:29.832 SpaceInvadersTutorial[4601:a0b] found match! 2013-09-23 17:43:29.860 SpaceInvadersTutorial[4601:a0b] Looking up 1 players
  • 22. Multiplayer Games Magnus Jahnensgd-ws13 22 Network Communication
  • 23. Multiplayer Games Magnus Jahnensgd-ws13 Sending data • Send data by calling sendData from class GKMatch • Takes NSData which is just an array of bytes • Data can be sent reliable or unreliable • Remember the networking guidelines mentioned before • Small package size • Lowest frequency • Network topologies • etc. 23
  • 24. Multiplayer Games Magnus Jahnensgd-ws13 Sending Reliable (TCP) • Guaranteed delivery • No out of order packets ➡ Easy to use • But may be slower! ➡ For infrequent messages which need to reach their destination! 24
  • 25. Multiplayer Games Magnus Jahnensgd-ws13 Sending Unreliable (UDP) • Faster than reliable • No guaranteed delivery • Maybe out of order packets ➡ For real time updates (e.g. position updates) 25
  • 26. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 2 26 • Implement the method sendEnemySpawned in MultiPlayerHelper.m • Use [self getRelativePosition:] to get a relative position to screen • Init a EnemySpawnedMessage and send it via [self sendMessage:] • Time: 5 minutes @interface EnemySpawnedMessage : Message ... - (id)initWithEnemyIndex:(NSUInteger)index atPosition:(CGPoint)position; ... @end Hint:
  • 27. Multiplayer Games Magnus Jahnensgd-ws13 Solution: TODO 2 27 MultiPlayerHelper.m - (void)sendEnemySpawned:(int)enemyIndex atPosition:(CGPoint)position { #warning TODO 2 send when an enemy/alien spawned CGPoint relativePosition = [self getRelativePosition:position]; EnemySpawnedMessage *message = [[EnemySpawnedMessage alloc] initWithEnemyIndex:enemyIndex atPosition:relativePosition]; [self sendMessage:message]; }
  • 28. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 3 28 • Implement the method parseEnemySpawned in MultiPlayerHelper.m • Use [self getAbsolutePosition:] to get an absolute position to screen • Use the property self.networkDelegate to notify the Game Scene • Time: 5 minutes @interface EnemySpawnedMessage : Message @property NSUInteger enemyIndex; @property CGPoint position; ... @end @protocol NetworkDelegate ... - (void)enemySpawned:(int)enemyIndex atPosition: (CGPoint)position; ... @end Hints:
  • 29. Multiplayer Games Magnus Jahnensgd-ws13 Solution: TODO 3 29 MultiPlayerHelper.m - (void)parseEnemySpawnedMessage:(EnemySpawnedMessage *)message { #warning TODO 3 parse the enemy message CGPoint absolutePosition = [self getAbsolutePosition:message.position]; [self.networkDelegate enemySpawned:message.enemyIndex atPosition:absolutePosition]; }
  • 30. Multiplayer Games Magnus Jahnensgd-ws13 Whats missing? • Player Position updates ➡ Good example where unreliable packages are useful 30
  • 31. Multiplayer Games Magnus Jahnensgd-ws13 How to deal with the Problems • Lost packages ➡ Just ignore them • Out of order packages ➡ Just use the most recent received information • These solutions apply for most scenarios! 31
  • 32. Multiplayer Games Magnus Jahnensgd-ws13 Problem: Out of Order Packages • Include a message counter in the position update message • Compare it with the message count we expect next ➡ Bigger or equal → Valid ➡ Otherwise we just drop the package 32
  • 33. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 4 33 MultiPlayerHelper.m - (void)sendPlayerPosition:(CGPoint)position { #warning TODO 4 send the player position unreliable self.outgoingCounter++; CGPoint relativePosition = [self getRelativePosition:position]; PlayerPositionUpdateMessage *message = [[PlayerPositionUpdateMessage alloc] initWithPosition:relativePosition andMessageCount:self.outgoingCounter]; [self sendMessageUnreliable:message]; }
  • 34. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 5 34 MultiPlayerHelper.m - (void)parsePlayerPositionUpdateMessage:(PlayerPositionUpdateMessage *)message { #warning TODO 5 parse the position update message // sorry, but out of order -> just ignore if(self.incomingCounter >= message.messageCount) { NSLog(@"received out of order position update!"); return; } CGPoint absolutePosition = [self getAbsolutePosition:message.playerPosition]; self.incomingCounter = message.messageCount; [self.networkDelegate playerPositionChanged:absolutePosition]; }
  • 35. Multiplayer Games Magnus Jahnensgd-ws13 35 Play!
  • 36. Multiplayer Games Magnus Jahnensgd-ws13 36 MultipeerConnectivity
  • 37. Multiplayer Games Magnus Jahnensgd-ws13 Overview 37 Session Session Session
  • 38. Multiplayer Games Magnus Jahnensgd-ws13 Important classes 38 MCAdvertiserAssistant MCBrowserView Controller MCSessionMCPeerID
  • 39. Multiplayer Games Magnus Jahnensgd-ws13 Overview 39 1 1 1 delegate 1 1 delegate 1 1 MultiPeerCommunication +findMatch() MCBrowserViewController +serviceType: NSString* +maximumNumberOfPeers +minimumNumberOfPeers MCAdvertiserAssistant +serviceType: NSString* +start() +stop() MCSession +sendData(NSData *) MCPeerID +playerName
  • 40. Multiplayer Games Magnus Jahnensgd-ws13 Bonjour • Apples implementation of Zeroconf networking • Used to find available services in a network using multicast ‣ Identified via the service type • Used for example in iTunes or to easily find network printers 40
  • 41. Multiplayer Games Magnus Jahnensgd-ws13 Presenting the UI 41 Passive via Advertiser Active via ViewController
  • 42. Multiplayer Games Magnus Jahnensgd-ws13 Change the Strategy! 42 #warning TODO change the strategy [MultiPlayerHelper sharedInstance].communicationStrategy = [[GameCenterCommunication alloc] init]; ViewController.m Change To [MultiPlayerHelper sharedInstance].communicationStrategy = [[MultiPeerCommunication alloc] initWithPlayerName:@"Your Name"];
  • 43. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 6 • Init a MCPeerID with self.playerName • Init a MCSession (property) with the peer ID • Do not forget to set the delegate! • Init a MCAdvertiserAssistant (property) with service type „space“, „nil“ as discovery Info and the session • Then start the Advertiser • Time: 7 minutes 43 MCPeerID MCSession MCAdvertiser Assistant
  • 44. Multiplayer Games Magnus Jahnensgd-ws13 Solution: TODO 6 44 - (void)setupSession { #warning TODO 6 setup up the MultipeerConnectivity Session MCPeerID *peer = [[MCPeerID alloc] initWithDisplayName:self.playerName]; self.session = [[MCSession alloc] initWithPeer:peer]; self.session.delegate = self; self.advertiserAssistant = [[MCAdvertiserAssistant alloc] initWithServiceType:@"space" discoveryInfo:nil session:self.session]; [self.advertiserAssistant start]; } MultiPeerCommunication.m
  • 45. Multiplayer Games Magnus Jahnensgd-ws13 Exercise: TODO 7 • First stop the Advertiser! • Init a MCBrowserViewController with Service Type „space“ and the property session • Do not forget to set the delegate and maximum and minimum number of peers • Present the ViewController via [Helper presentViewController:] • Time: 7 minutes 45 MCPeerID MCSession MCBrowserView Controller
  • 46. Multiplayer Games Magnus Jahnensgd-ws13 Solution: TODO 7 46 - (void)findMatch { #warning TODO 7 find a match/other peers using MultipeerConnectivity [self.advertiserAssistant stop]; MCBrowserViewController *viewController = [[MCBrowserViewController alloc] initWithServiceType:@"space" session:self.session]; viewController.delegate = self; viewController.maximumNumberOfPeers = 2; viewController.minimumNumberOfPeers = 2; [Helper presentViewController:viewController]; } MultiPeerCommunication.m
  • 47. Multiplayer Games Magnus Jahnensgd-ws13 47 Play!
  • 48. Multiplayer Games Magnus Jahnensgd-ws13 Summary • You are now able to build a multiplayer game! Congratulations! • You know why Game Center and MultipeerConnectivity are useful • You know how you can find matches (other players) with the standard View Controllers • You know how to send and receive data over a GKMatch or MCSession • You know where you should pay attention at when designing a multiplayer real time game 48
  • 49. Multiplayer Games Magnus Jahnensgd-ws13 ‣ Let the user decide 49 Game Center • Server infrastructure supplied by Apple • Wide community • Available on iOS and OS X • More features available like leaderboards or voice chat • Dependent on Apple Servers • No nearby players MultipeerConnectivity • No server needed • Different communication Methods (Bluetooth and Wifi) • Seems to work better and faster • Only nearby devices • Available only on iOS • Not optimized for gaming
  • 50. Multiplayer Games Magnus Jahnensgd-ws13 Some tips • Use my strategy pattern • Enable Game Center/MultipeerConnectivity in the Xcode project • Register your app Bundle ID in iTunes Connect • Check if the sandbox is online • https://sandbox.itunes.apple.com/verifyReceipt 50
  • 51. Multiplayer Games Magnus Jahnensgd-ws13 Helpful links • Official Apple Game Center Guide • https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/ GameKit_Guide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008304-CH1- SW1 • How to Make a simple multiplayer game by Ray Wenderlich • http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with- game-center-tutorial-part-12 • Nearby Networking with MultipeerConnectivity (Video) • https://developer.apple.com/wwdc/videos/index.php?id=708 • About Multipeer Connectivity by Apple • https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/ Reference/MultipeerConnectivityFramework/Introduction/Introduction.html • Snap (card game by Ray Wenderlich) • GameKit API deprecated, but good example how to exchange packages! • http://www.raywenderlich.com/12735 51
  • 52. Multiplayer Games Magnus Jahnensgd-ws13 Thank you! Questions? Do not hesitate to ask! 52
  • 53. Multiplayer Games Magnus Jahnensgd-ws13 References • https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Introduction/Introduction.html#// apple_ref/doc/uid/TP40008304-CH1-SW1 • https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Matchmaking/Matchmaking.html#// apple_ref/doc/uid/TP40008304-CH9-SW1 • https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework • http://www.raywenderlich.com/12735 • http://iphonedevsdk.com/forum/iphone-sdk-development/96012-is-the-sandbox-down-i-keep-getting-http-unavailable.html • http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12 • http://devstreaming.apple.com/videos/wwdc/2013/708xbx3x7xusbzidl0j3acxest/708/708.pdf?dl=1 • https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/Introduction/ Introduction.html • https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/_index.html#// apple_ref/doc/uid/TP40013328 • http://en.wikipedia.org/wiki/Bonjour_(software) • http://en.wikipedia.org/wiki/OSI_model • http://en.wikipedia.org/wiki/User_Datagram_Protocol • http://en.wikipedia.org/wiki/Transmission_Control_Protocol • http://en.wikipedia.org/wiki/Game_Center 53
  • 54. Multiplayer Games Magnus Jahnensgd-ws13 Images • Slide 3: Game Center Icon • http://www.icreatemagazine.com/wp-content/uploads/2013/08/Game-Center2.png • Slide 4 + 5: Example Applications • http://1.bp.blogspot.com/-VN8uai_77pg/TZTNonsIzmI/AAAAAAAAAxY/qdVvIjwUNGA/s1600/Doodle%2BJump%2BMultiplayer.jpg • https://itunes.apple.com/de/app/real-racing-3/id556164350?mt=8 • https://itunes.apple.com/us/app/word-rally/id447075138?mt=8 • https://itunes.apple.com/de/app/carcassonne/id375295479?mt=8 • Slide 6 + 37: MultipeerConnectivity • http://devstreaming.apple.com/videos/wwdc/2013/708xbx3x7xusbzidl0j3acxest/708/708.pdf?dl=1 • Slide 10: Network topologies: • https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Art/ network_topologies_2x.png • Slide 40: Bonjour Icon • https://devimages.apple.com.edgekey.net/bonjour/images/bonjour-hero.png • Slide 52: MultipeerConnectivity • http://www.theonliner.de/wp-content/uploads/2013/07/multipeer_004_220-e1373416225609.jpg • Plus and minus signs: • http://mountainss.files.wordpress.com/2012/12/plus-sign.png?w=256 • http://www.omgomfg.com/file/pic/photo/2012/09/rebelius-minus-sign.png • All other images were made by myself 54