AvatarEventHandler

AvatarEventHandler

AvatarEventHandler Behavior Module

The Microverse system automatically attaches a behavior module named AvatarEventHandler to the Avatar. Its default implementation is stored in behaviors/croquet/avatarEvents.js, but you can create a behavior with a similar structure to override the default functionality of some methods defined at AvatarPawn.

When the card spec for the avatar has the avatarEventHandler property, the behavior module with the name is used (instead of a module named AvatarEventHandler. You can provide a custom action for a known method by defining a method at the pawn side behavior called AvatarPawn. (cf. behaviors/croquet/halfBodyAvatar.js in the source code).

Currently the following methods of the base AvatarPawn can be overridden. (In the source code the methods with this.call(...handlerModuleName...) lines checks if the named method exists in the behavior and calls if it does.)

Methods

# startMotion(dx, dy)

Called when the shell sends the motion-start DOM message from the Microverse shell, typically when the joystick is pressed down.

Parameters:
Name Type Description
dx number

the offset of joystick knob

dy number

the offset of joystick knob

# updateMotion(dx, dy)

Called repeatedly when the shell sends the motion-update DOM message from the Microverse shell, typically when the joystick is moved from the off-center.

Parameters:
Name Type Description
dx number

the offset of joystick knob

dy number

the offset of joystick knob

# endMotion(dx, dy)

Called when the shell sends the motion-end DOM message from the Microverse shell, typically when the joystick is released.

Parameters:
Name Type Description
dx number

the offset of joystick knob

dy number

the offset of joystick knob

# walkLook()

This method specifies the global camera position. The implementation can use various properties such as the global transformation of the avatar, lookPitch and other properties that the behavior defines.

Returns:

Matrix4

# pointerDown(evt)

Implementing them at the AvatarPawn overrides their actions. Note that the first responder and last responder mechanism is involved so some methods expects certain patterns. In general, you can simply copy the default implementation in src/avatar.js into your own behavior file as ther starting point for your own custom implementation.

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# pointerUp(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# pointerMove(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# pointerMove(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# pointerTap(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# pointerWheel(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# pointerDoubleDown(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# keyDown(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# keyUp(evt)

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# mapOpacity()

This method controls the opacity used to render avatars. Typically a remote avatar close to yours become translucent. the custom implementation of mapOpacity defined at the AvatarPawn maps the value in the [0, 1] range.

Returns:

a number to represent modified opacity between [0, 1]