Package sfs2x.client.requests.mmo
Class SetUserPositionRequest
- java.lang.Object
-
- sfs2x.client.requests.BaseRequest
-
- sfs2x.client.requests.mmo.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 Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_MINUS_ITEM_LIST
API internal usage onlystatic java.lang.String
KEY_MINUS_USER_LIST
API internal usage onlystatic java.lang.String
KEY_PLUS_ITEM_LIST
API internal usage onlystatic java.lang.String
KEY_PLUS_USER_LIST
API internal usage onlystatic java.lang.String
KEY_ROOM
API internal usage onlystatic java.lang.String
KEY_VEC3D
API internal usage only-
Fields inherited from class sfs2x.client.requests.BaseRequest
AddBuddy, AdminMessage, AutoJoin, BanUser, BlockBuddy, CallExtension, ChangeRoomCapacity, ChangeRoomName, ChangeRoomPassword, ClusterInviteUsers, ClusterJoinOrCreate, CreateRoom, CreateSFSGame, FindRooms, FindUsers, GameServerConnectionRequired, GenericMessage, GetRoomList, GoOnline, Handshake, InitBuddyList, InvitationReply, InviteUser, JoinRoom, JoinRoomInvite, KEY_ERROR_CODE, KEY_ERROR_PARAMS, KickUser, LeaveRoom, Login, Logout, ManualDisconnection, ModeratorMessage, ObjectMessage, PingPong, PlayerToSpectator, PrivateMessage, PublicMessage, QuickJoinGame, QuickJoinOrCreateRoom, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
-
-
Constructor Summary
Constructors Constructor Description SetUserPositionRequest(Vec3D position, Room room)
Creates a new SetUserPositionRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(ISmartFox sfs)
void
validate(ISmartFox sfs)
-
Methods inherited from class sfs2x.client.requests.BaseRequest
getId, getMessage, getTargetController, isEncrypted, setEncrypted, setId, setTargetController
-
-
-
-
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
-
-