Class SFS2X.Requests.System.SpectatorToPlayerRequest

Turns the current user from spectator to player in a Game Room.

Class Summary
Constructor Attributes Constructor Name and Description
 
Creates a new SpectatorToPlayerRequest instance.

Class Detail

SFS2X.Requests.System.SpectatorToPlayerRequest(targetRoom)
Creates a new SpectatorToPlayerRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

This request turns the current user from spectator to player in a Game Room. If the operation is successful, all the users in the target Room are notified with the spectatorToPlayer event. The operation could fail if no player slots are available in the Game Room at the time of the request; in this case the spectatorToPlayerError event is dispatched to the requester's client.

The following example turns the current user from spectator to player in the last joined Game Room:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.SPECTATOR_TO_PLAYER, onSpectatorToPlayerSwitch, this);
	sfs.addEventListener(SFS2X.SFSEvent.SPECTATOR_TO_PLAYER_ERROR, onSpectatorToPlayerSwitchError, this);
	
	// Switch spectator to player
	sfs.send(new SFS2X.Requests.System.SpectatorToPlayerRequest());
}

function onSpectatorToPlayerSwitch(evtParams)
{
	console.log("Spectator " + evtParams.user + " is now a player");
}

function onSpectatorToPlayerSwitchError(evtParams)
{
	console.log("Unable to become a player due to the following error: " + evtParams.errorMessage);
}
Parameters:
{SFSRoom} targetRoom Optional, Default: null
The SFSRoom object corresponding to the Room in which the spectator should be turned to player. If null, the last Room joined by the user is used.
See also:
SFS2X.SmartFox#send
SFS2X.Entities.SFSRoom
SFS2X.SFSEvent.SPECTATOR_TO_PLAYER
SFS2X.SFSEvent.SPECTATOR_TO_PLAYER_ERROR
SFS2X.Requests.System.PlayerToSpectatorRequest