DynamicObject

DynamicObject

DynamicObject is the base class of the game's objects, for games which rely on SimplePhysicsEngine. It defines the base object which can move around in the game world. The extensions of this object (the subclasses) will be periodically synchronized from the server to every client.

The dynamic objects have pseudo-physical properties, which allow the client to extrapolate the position of dynamic objects in-between server updates.

Constructor

new DynamicObject(gameEngine, options, props)

Creates an instance of a dynamic object. NOTE: all subclasses of this class must comply with this constructor signature. This is required because the engine will create temporary instances when syncs arrive on the clients.

Parameters:
Name Type Description
gameEngine GameEngine

the gameEngine this object will be used in

options Object

options for the new object. See GameObject

props Object

properties to be set in the new object

Properties
Name Type Description
position TwoVector

position vector

velocity TwoVector

velocity vector

Source:

Members

(static) maxSpeed :Number

The maximum velocity allowed. If returns null then ignored.

Source:

(static) netScheme :Object

The netScheme is a dictionary of attributes in this game object. The attributes listed in the netScheme are those exact attributes which will be serialized and sent from the server to each client on every server update. The netScheme member is implemented as a getter.

You may choose not to implement this method, in which case your object only transmits the default attributes which are already part of DynamicObject. But if you choose to add more attributes, make sure the return value includes the netScheme of the super class.

Source:
Example
static get netScheme() {
      return Object.assign({
          mojo: { type: Serializer.TYPES.UINT8 },
        }, super.netScheme);
    }

acceleration :Number

acceleration per step

Source:

affectedByGravity :Boolean

Whether this object is affected by gravity.

Source:

angle :Number

object orientation angle in degrees

Source:

friction :TwoVector

The friction coefficient. Velocity is multiplied by this for each step. Default is (1,1)

Source:

height :Number

Object Height for collision detection purposes. Default is 1

Source:

isAccelerating :Boolean

should accelerate by DynamicObject#acceleration on next step

Source:

isRotatingLeft :Boolean

should rotate left by DynamicObject#rotationSpeed on next step

Source:

isRotatingRight :Boolean

should rotate right by DynamicObject#rotationSpeed on next step

Source:

playerId :Number

ID of player who created this object

Source:

rotationSpeed :Number

angle rotation per step

Source:

width :Number

Object width for collision detection purposes. Default is 1

Source:

Methods

bendingToString() → {String}

Formatted textual description of the game object's current bending properties.

Source:
Returns:

description - a string description

Type
String

toString() → {String}

Formatted textual description of the dynamic object. The output of this method is used to describe each instance in the traces, which significantly helps in debugging.

Source:
Returns:

description - a string describing the DynamicObject

Type
String