Packagecom.smartfoxserver.v2.requests.game
Classpublic class CreateSFSGameRequest
InheritanceCreateSFSGameRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Creates a new public or private game, including player matching criteria, invitations settings and more.

A game is created through the istantiation of a SFSGame on the server-side, a specialized Room type that provides advanced features during the creation phase of a game. Specific game-configuration settings are passed by means of the SFSGameSettings class.

If the creation is successful, a roomAdd event is dispatched to all the users who subscribed the Group to which the Room is associated, including the game creator. Otherwise, a roomCreationError event is returned to the creator's client.

Also, if the settings passed in the SFSGameSettings object cause invitations to join the game to be sent, an invitation event is dispatched to all the recipient clients.

Check the SmartFoxServer 2X documentation for a more in-depth overview of the GAME API.

View the examples

See also

SFSGameSettings
roomAdd event
roomCreationError event
invitation event


Public Methods
 MethodDefined By
  
Creates a new CreateSFSGameRequest instance.
CreateSFSGameRequest
Constructor Detail
CreateSFSGameRequest()Constructor
public function CreateSFSGameRequest(settings:SFSGameSettings)

Creates a new CreateSFSGameRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters
settings:SFSGameSettings — An object containing the SFSGame configuration settings.

See also

Examples
The following example creates a new game:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.ROOM_ADD, onRoomCreated);
         sfs.addEventListener(SFEvent.ROOM_CREATION_ERROR, onRoomCreationError);
         
         // Prepare the settings for a public game
         var settings:SFSGameSettings = new SFSGameSettings("DartsGame");
         settings.maxUsers = 2;
         settings.maxSpectators = 8;
         settings.isPublic = true;
         settings.minPlayersToStartGame = 2;
         settings.notifyGameStarted = true;
         
         // Set the matching expression for filtering users joining the Room
         settings.playerMatchExpression = new MatchExpression("bestScore", NumberMatch.GREATER_THAN, 100);
         
         // Set a Room Variable containing the description of the game
         settings.variables = [new SFSRoomVariable("desc", "Darts game, public, bestScore > 100")];
         
         // Create the game
         sfs.send(new CreateSFSGameRequest(settings));
     }
     
     private function onRoomCreated(evt:SFSEvent):void
     {
         trace("Room created: " + evt.params.room);
     }
     
     private function onRoomCreationError(evt:SFSEvent):void
     {
         trace("Room creation failed: " + evt.params.errorMessage);
     }