Click or drag to resize

SetUserPositionRequest Class

Updates the User position inside an MMORoom.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.Requests.MMOSetUserPositionRequest

Namespace:  Sfs2X.Requests.MMO
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class SetUserPositionRequest : BaseRequest
Constructors
  NameDescription
Public methodSetUserPositionRequest(Vec3D)
See SetUserPositionRequest(Vec3D, Room) constructor.
Public methodSetUserPositionRequest(Vec3D, Room)
Creates a new SetUserPositionRequest instance.
Top
Remarks
MMORooms represent virtual environments and can host any number of users. Based on their position, the system allows users within a certain range from each other (Area of Interest, or AoI) to interact.

This request allows the current user to update his position inside the MMORoom, which in turn will trigger a PROXIMITY_LIST_UPDATE event for all users that fall within his AoI.

Examples
The following example changes the position of the user in a 2D coordinates space and handles the related event:
private void UpdatePlayerPosition(int px, int py)
{
    var newPos = new Vec3D(px, py);
    sfs.Send(new SetUserPositionRequest(newPos));
}

private void OnProximityListUpdate(BaseEvent evt)
{
    var added = (List<User>) evt.params["addedUsers"];
    var removed = (List<User>) evt.params["removedUsers"];

    // Add users that entered the proximity list
    foreach (User user in added)
    {
        // Obtain the coordinates at which the user "appeared" in our range
        Vec3D entryPoint = user.AoiEntryPoint;

        // Add new avatar in the scene
        var avatarSprite = new AvatarSprite();
        avatarSprite.x = entryPoint.px;
        avatarSprite.y = entryPoint.py;
        ...
    }

    // Remove users that left the proximity list
    foreach (User user in removed)
    {
        // Remove the avatar from the scene
        ...
    }
}
See Also