DynamicObject

DynamicObject

DynamicObject is the base class of the game's objects, for 2D 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 1: do not add logic to subcclasses of this function, instead, create an instance and assign attributes to the new objects. NOTE 2: 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

height Number

object height

width Number

object width

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: BaseTypes.TYPES.UINT8 },
        }, super.netScheme);
    }

acceleration :Number

Deprecated:
  • since version 3.0.8 acceleration per step
Source:

angle :Number

object orientation angle in degrees

Source:

bending

Each object class can define its own bending overrides. return an object which can include attributes: position, velocity, and angle. In each case, you can specify a min value, max value, and a percent value. { @see GameObject.bending }

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

Deprecated:
Source:

isRotatingLeft :Boolean

Deprecated:
Source:

isRotatingRight :Boolean

Deprecated:
Source:

isStatic :Number

Determine if the object is static (i.e. it never moves, like a wall). The value 0 implies the object is dynamic. Default is 0 (dynamic).

Source:

rotationSpeed :Number

Deprecated:
  • since version 3.0.8 angle rotation per step
Source:

width :Number

Object width for collision detection purposes. Default is 1

Source:

Methods

accelerate(acceleration) → {DynamicObject}

accelerate along the direction that the object is facing

Parameters:
Name Type Description
acceleration Number

the acceleration

Source:
Returns:

return this object

Type
DynamicObject

bendingToString() → {String}

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

Source:
Returns:

description - a string description

Type
String

collidesWith(other) → {Boolean}

Determine if this object will collide with another object. Only applicable on "bruteForce" physics engine.

Parameters:
Name Type Description
other DynamicObject

DynamicObject

Source:
Returns:

true if the two objects collide

Type
Boolean

syncTo(other)

Copy the netscheme variables from another DynamicObject. This is used by the synchronizer to create temporary objects, and must be implemented by all sub-classes as well.

Parameters:
Name Type Description
other DynamicObject

DynamicObject

Source:

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

turnLeft(deltaAngle) → {DynamicObject}

turn object counter-clock-wise

Parameters:
Name Type Description
deltaAngle Number

the angle to turn, in degrees

Source:
Returns:

return this object

Type
DynamicObject

turnRight(deltaAngle) → {DynamicObject}

turn object clock-wise

Parameters:
Name Type Description
deltaAngle Number

the angle to turn, in degrees

Source:
Returns:

return this object

Type
DynamicObject