Click or drag to resize

ObjectMessageRequest Class

Sends an object containing custom data to all users in a Room, or a subset of them.
Inheritance Hierarchy
SystemObject
  BaseRequest
    GenericMessageRequest
      Sfs2X.RequestsObjectMessageRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class ObjectMessageRequest : GenericMessageRequest
Constructors
  NameDescription
Public methodObjectMessageRequest(ISFSObject)
See ObjectMessageRequest(ISFSObject, Room, ICollection<User>) constructor.
Public methodObjectMessageRequest(ISFSObject, Room)
See ObjectMessageRequest(ISFSObject, Room, ICollection<User>) constructor.
Public methodObjectMessageRequest(ISFSObject, Room, ICollectionUser)
Creates a new ObjectMessageRequest instance.
Top
Remarks
The data object is delivered to the selected users (or all users excluding the sender) inside the target Room by means of the OBJECT_MESSAGE event. It can be useful to send game data, like for example the target coordinates of the user's avatar in a virtual world.
Examples
The following example sends the player's character movement coordinates and handles the respective event:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.OBJECT_MESSAGE, OnObjectMessage);

    // Send a game move to all players
    ISFSObject dataObj = new SFSObject();
    dataObj.PutInt("x", myAvatar.x);
    dataObj.PutInt("y", myAvatar.y);
    sfs.Send( new ObjectMessageRequest(dataObj) );
}

void OnObjectMessage(BaseEvent evt) {
    ISFSObject dataObj = (SFSObject)evt.Params["message"];
    int x = dataObj.GetInt("x");
    int y = dataObj.GetInt("y");

    // etc...
}
See Also