Class: ScreenArranger

plugins/screens. ScreenArranger

This is the base class for arranging players of the given session to one big playing field. It will add a screen attribute to every joined player.

Feel free to extend this class to create your own ScreenArranger. You can use module:plugins/screens.HorizontalArranger as example implementation.

new ScreenArranger(Session)

Parameters:
Name Type Description
Session module:shared/session~Session that contains the players that should be arranged into one big screen.
Source:

Mixes In

Members

<readonly> height :integer

total height of the big screen in pixel
Type:
  • integer
Source:

<readonly> session :module:shared/session~Session

Session that is getting arranged into one big game screen
Type:
Source:

<readonly> width :integer

total width of the big screen in pixel
Type:
  • integer
Source:

Methods

<abstract> arrange()

This method is called by the refresh method by default. It does nothing for this base class and should be overridden by every child class.

Please make sure to update the positions of every players screen here.
Source:

getPlayerAtCoords(x, y) → {module:shared/player~Player}

Parameters:
Name Type Description
x integer global x position in pixel
y integer global y position in pixel
Source:
Returns:
player object whose screen lies beneath the given coordinates or null when no player can be found at this position
Type
module:shared/player~Player

globalRectToLocals(x, y, width, height) → {Array}

Determines which Player overlaps with the given rectangle.
Parameters:
Name Type Description
x integer global x-coordinate of the upper left corner of the rectangle in pixel
y integer global y-coordinate of the upper left corner of the rectangle in pixel
width integer width of the rectangle in pixel
height integer height of the rectangle in pixel
Source:
See:
Returns:
list of local objects of the form { x: localX, y: localY, player: hitPlayer }. X and y are the upper-left corner of the given rectangle in the players local coordinate system.
Type
Array

globalToLocal(x, y) → {object|null}

Determines which Player overlaps with the given point and returns it in his local coordinates.
Parameters:
Name Type Description
x integer global x-coordinate of in pixel
y integer global y-coordinate of in pixel
Source:
See:
Returns:
local object of the form { x: localX, y: localY, player: hitPlayer } or null.
Type
object | null

isPlayerHit(player, x, y) → {boolean}

Parameters:
Name Type Description
player module:shared/player~Player any player object connected to the arranged session
x integer global x position in pixel
y integer global y position in pixel
Source:
Returns:
true if the given coordinates lie within the screen of the given player
Type
boolean

localToGlobal(player, x, y) → {object}

Converts local pixel coordinates to global ones.
Parameters:
Name Type Description
player module:shared/player~Player player instance the local coordinates refer to
x integer local x position in pixel
y integer local y position in pixel
Source:
Returns:
{ x: globalX, y: globalY } or null if the given player is no part of this arranger
Type
object

onPlayerJoined(event)

This method is callen whenever a new player joins the session. Feel free to override. In this case you may want to create a new screen for the player and call your refresh method.
Parameters:
Name Type Description
event
Source:

onPlayerLeft(event)

This method is callen whenever a new player leaves the session. Feel free to override. In this case you may want to call your refresh method.
Parameters:
Name Type Description
event
Source:

recaculateDimentions()

This method is called by the refresh method by default. It takes the global position and dimentions of every player into account to update the global playing field width and height accordingly.
You may override this method or call it from any overridden method.
Source:

refresh()

This method by default gets called whenever a new player joins the underlying session. It calls arrange and recaculateDimentions.
You can override this method to write your own screen arranger. In this case please make sure to arrange every player and update the dimentions of the whole playing field accordingly.
Source:

Events

arrangementChanged

Fired when the screen layout changes. This may be because a player joined or left the session.
Source: