new Match(serviceName, matchData)
This type provides a transmission network between a group of users. The match might be returned before connections have been established between players. At this stage, all the players are in the process of connecting to each other. Always check the getExpectedPlayerCount value before starting a match. When its value reaches zero, all expected players are connected, and your game can begin the match. Do not forget to call the start method of the match when your game is ready to process received messages via onMatchDataReceived listener.
Parameters:
Name | Type | Description |
---|---|---|
serviceName |
string | The name of the native ext object extension property name. |
matchData |
object | The match data received from the native service bridge. |
Methods
-
<static> disconnect()
-
Disconnects the local player from the match and releases the match. Calling disconnect notifies other players that you have left the match.
-
<static> getExpectedPlayerCount() → {number}
-
Returns the remaining players count who have not yet connected to the match.
Returns:
The remaining number of players who have not yet connected to the match.
- Type
- number
-
<static> getLocalPlayerID() → {string}
-
Gets the local playerID taking part in the match.
Returns:
the playerID attached to the match manager.
- Type
- string
-
<static> getPlayerID() → {string}
-
Gets the local playerID taking part in the match.
Returns:
the playerID attached to the match manager.
- Type
- string
-
<static> getPlayerIDs() → {array}
-
Returns an array with all the player identifiers taking part in the match.
Returns:
The player identifiers for the players in the match.
- Type
- array
-
<static> requestPlayersInfo(callback)
-
Requests additional information of the current players in the match.
Parameters:
Name Type Description callback
function The callback function. Response params: players array and error
-
<static> sendData(data, playerIDs, sendMode) → {boolean}
-
Transmits data to a list of connected players. The match queues the data and transmits it when the network becomes available.
Parameters:
Name Type Argument Description data
string The data to transmit
playerIDs
array An array containing the identifier strings for the list of players who should receive the data.
sendMode
Cocoon.Multiplayer.SendDataMode <optional>
The optional Cocoon.Multiplayer.SendDataMode value. The default value is RELIABLE.
Returns:
TRUE if the data was successfully queued for transmission; FALSE if the match was unable to queue the data.
- Type
- boolean
-
<static> sendDataToAllPlayers(data, sendMode) → {boolean}
-
Transmits data to all players connected to the match. The match queues the data and transmits it when the network becomes available.
Parameters:
Name Type Argument Description data
string The data to transmit.
sendMode
Cocoon.Multiplayer.SendDataMode <optional>
The optional Cocoon.Multiplayer.SendDataMode value. The default value is RELIABLE.
Returns:
TRUE if the data was successfully queued for transmission; FALSE if the match was unable to queue the data.
- Type
- boolean
-
<static> start()
-
Starts processing received messages. The user must call this method when the game is ready to process messages. Messages received before being prepared are stored and processed later.
Events
-
On restore products callbacks
-
Allows to listen to events about the restoring process.
- The callback 'dataReceived'
- The callback 'stateChanged'
- The callback 'connectionWithPlayerFailed' allows listening to events called when a netowrk connection with a player fails
- The callback 'failed' allows listening to events called when the match fails.
Example