namespace NT { /**
     * Represents the data used to configure this behavior.
     */ export class KeyboardMovementBehaviorData implements IBehaviorData { /**
         * The name of this behavior.
         */ public name : string ; /**
         * The movement speed to be applied when a key is held down. Default: 0.1
         */ public speed : number = 0.1 ; param json public setFromJson ( json ) { if ( json . name === undefined ) { throw new Error ( "Name must be defined in behavior data." ) ; } this . name = String ( json . name ) ; if ( json . speed !== undefined ) { this . speed = Number ( json . speed ) ; } } } /**
     * The builder for a KeyboardMovement behavior.
     */ export class KeyboardMovementBehaviorBuilder implements IBehaviorBuilder { /**
         * The behavior type.
         */ public get type ( ) : string { return "keyboardMovement" ; } param json public buildFromJson ( json ) { let data = new KeyboardMovementBehaviorData ( ) ; data . setFromJson ( json ) ; return new KeyboardMovementBehavior ( data ) ; } } /**
     * A behavior which, when a key is held down, moves the object to which it is attached
     * at the rate of the configured speed.
     */ export class KeyboardMovementBehavior extends BaseBehavior { /**
         * The speed a which to move.
         */ public speed : number = 0.1 ; param data public constructor ( data ) { super ( data ) ; this . speed = data . speed ; } param time public update ( time ) { if ( InputManager . isKeyDown ( Keys . LEFT ) ) { this . _owner . transform . position . x -= this . speed ; } if ( InputManager . isKeyDown ( Keys . RIGHT ) ) { this . _owner . transform . position . x += this . speed ; } if ( InputManager . isKeyDown ( Keys . UP ) ) { this . _owner . transform . position . y -= this . speed ; } if ( InputManager . isKeyDown ( Keys . DOWN ) ) { this . _owner . transform . position . y += this . speed ; } super . update ( time ) ; } } BehaviorManager . registerBuilder ( new KeyboardMovementBehaviorBuilder ( ) ) ; }