MultiUser Mouse Pointer Question

Added by Murat Pak 654 days ago

We're trying to build a multiuser mouse chat experience.
However, we want the mouse "poisitions" to be defined as "ratio" (like xRatio yRatio) to make it work in all resolutions (without going out of the boundaries of the stage).
We were able to convert (/manipulate) the sent mouse positions to ratio (instead of direct coordinates) by editing the PointerPositionBroadcaster.as, however, we can not reach the positions that are taken from the server to place the "mouse pointer". So we're unable to convert (/manipulate) them from ratio back to coordinates.

Other than this, we will need the X and Y attributes of each "connected client" to be able to add "chat bubbles" to them.

What is the route we should follow ?

Thank you !


Replies

RE: MultiUser Mouse Pointer Question - Added by Murat Pak 654 days ago

In other words - where is "POS_LIST" being received ? And how can we acess to that attribute ?

RE: MultiUser Mouse Pointer Question - Added by colin moock 653 days ago

positions are sent in PositionBroadcaster's sendTimerListener():

    protected function sendTimerListener (e:TimerEvent):void {
      if (reactor.isReady()) {
        if (positions.length > 0) {
          reactor.self().setAttribute(
            positionListAttributeName,
            positions.serialize(),
            scope);
        }
        positions.clear();
      }
    }

positions can be received by any code with access to the client who's positions are changing. for example, the Avatar class expects a reference to a client object. it receives that reference via setClient(), which registers to be notified when the client's POS_LIST attribute changes as follows:

client.addEventListener(AttributeEvent.UPDATE, updateAttributeListener);

here's the corresponding event listener:

    protected function updateAttributeListener (e:AttributeEvent):void {
      var id:String = IClient(e.target).getClientID();
      var avatar:Avatar;
      var posList:PositionList = new PositionList();

      if (e.getChangedAttr().name == positionListAttributeName
          && e.getChangedAttr().scope == positionListAttributeScope) {
        posList.deserialize(e.getChangedAttr().value);
        // Update the user's current position.
        addPositions(posList);
      }
    }

colin

RE: MultiUser Mouse Pointer Question - Added by Murat Pak 652 days ago

Thank you very much for the detailed explanation

RE: MultiUser Mouse Pointer Question - Added by Murat Pak 647 days ago

One more question.
Where is the time that the script positions the avatar for the first time ?
I thought it was "nextposition" but it seems like its not...

RE: MultiUser Mouse Pointer Question - Added by colin moock 647 days ago

that happens in the Avatar's setClient() method. look for setPosition() below:

    public function setClient (client:IClient):void {
      var oldClient:IClient = this.client;
      this.client = client;
      if (oldClient == client) {
        return;
      }
      if (oldClient != null) {
        oldClient.removeEventListener(AttributeEvent.UPDATE, 
          updateAttributeListener);
      }
      if (client != null) {
        client.addEventListener(AttributeEvent.UPDATE, 
          updateAttributeListener);
        var posList:PositionList = new PositionList();
        posList.deserialize(client.getAttribute(positionListAttributeName, 
                                                positionListAttributeScope));
        setPosition(posList.getPositionAt(0).x, posList.getPositionAt(0).y);
        posList.shift();

        if (fader.duration > 0) {
          this.alpha = 0;
          fader.setValue("alpha", 1);
        }
      }
    }

RE: MultiUser Mouse Pointer Question - Added by Murat Pak 647 days ago

oh, thank you very much. As I can see from this place, there is no way to position the avatar BEFORE the connection with the server (and the room) is mad. Here is the problem I'm having:

I'm creating a mouse-chat application. Basically, I want messages to be displayed on "avatars".
I made the system that sends the msssages to the textboxes inside avatars. However, the problem I'm having is: if the person tries to type a message AFTER connecting to te server but BEFORE moving its mouse, I get a null exception (because the message can not be sent to the avatar which is not placed YET because the first placement is made with some kind of an update event ?).

I dont know the problem, actually, but I want to place the self avatar before the first mouse movement. How can it be possible ?

RE: MultiUser Mouse Pointer Question - Added by colin moock 646 days ago

Avatar is a Sprite subclass, so you can set its x and y any time you like. however, i wouldn't show the current user's avatar or accept any inputs until you know the current client has joined the chat room. the source for reactorgui is included in the download. it's primarily intended as an example on which to build, so you'll have to customize it if you have specific needs that are not being met by the built-in features.

colin