PhysicalObject2D

PhysicalObject2D

The PhysicalObject2D is the base class for physical game objects in 2D Physics

Constructor

new PhysicalObject2D(gameEngine, options, props)

Creates an instance of a physical object. Override to provide starting values for position, velocity, angle and angular velocity. 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

angle Number

orientation angle

mass Number

the mass

angularVelocity Number

angular velocity

Source:

Members

(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 PhysicalObject2D. 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);
    }

bending

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

Source:

Methods

onAddToWorld()

Called after the object is added to to the game world. This is the right place to add renderer sub-objects, physics sub-objects and any other resources that should be created

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 PhysicalObject2D

Type
String