Class SetUserPositionRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class SetUserPositionRequest
    extends BaseRequest
    Updates the User position inside an MMORoom.

    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 SFSEvent.PROXIMITY_LIST_UPDATE event for all users that fall within his AoI.

    Example: The following example changes the position of the user in a 2D coordinates space:

     private void someMethod()
     {
     
      // Setup a listener for the event
            sfs.addEventListener(SFSEvent.PROXIMITY_LIST_UPDATE, new IEventListener() 
            {
                    public void dispatch(BaseEvent evt) throws SFSException 
                    {
                            List<Users> added = (List<Users>) getArguments().get("addedUsers");
                            List<Users> removed = (List<Users>) getArguments().get("removedUsers");
     
                            // Add users that entered the proximity list
                            for (User user : added)
                            {
                                    // Obtain the coordinates at which the user "appeared" in our range
                                    Vec3D entryPoint = user.getAOIEntryPoint();
     
                                    // Add new avatar on screen
                                    AvatarSprite avatarSprite = new AvatarSprite();
                                    avatarSprite.x = entryPoint.intX();
                                    avatarSprite.y = entryPoint.intY();
                                    ...
                            }
     
                            // Remove users that left the proximity list
                            for (User user : removed)
                            {
                                    // Remove the avatar from stage
                                    ...
                            }
             }
            });
      
      // Set our current position in the Map
      Vec3D newPos = new Vec3D(px, py);
            sfs.send(new SetUserPositionRequest(newPos));
     
     }  
     
    See Also:
    SFSEvent.PROXIMITY_LIST_UPDATE, MMORoom, Vec3D
    • Field Detail

      • KEY_ROOM

        public static final java.lang.String KEY_ROOM
        API internal usage only
        See Also:
        Constant Field Values
      • KEY_VEC3D

        public static final java.lang.String KEY_VEC3D
        API internal usage only
        See Also:
        Constant Field Values
      • KEY_PLUS_USER_LIST

        public static final java.lang.String KEY_PLUS_USER_LIST
        API internal usage only
        See Also:
        Constant Field Values
      • KEY_MINUS_USER_LIST

        public static final java.lang.String KEY_MINUS_USER_LIST
        API internal usage only
        See Also:
        Constant Field Values
      • KEY_PLUS_ITEM_LIST

        public static final java.lang.String KEY_PLUS_ITEM_LIST
        API internal usage only
        See Also:
        Constant Field Values
      • KEY_MINUS_ITEM_LIST

        public static final java.lang.String KEY_MINUS_ITEM_LIST
        API internal usage only
        See Also:
        Constant Field Values
    • Constructor Detail

      • SetUserPositionRequest

        public SetUserPositionRequest​(Vec3D position,
                                      Room room)
        Creates a new SetUserPositionRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        position - The user position.
        room - The MMORoom object corresponding to the Room where the position should be set; if null, the last Room joined by the user is used.
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), MMORoom, Vec3D
    • Method Detail

      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
                     throws com.smartfoxserver.v2.exceptions.SFSException
        Throws:
        com.smartfoxserver.v2.exceptions.SFSException