1 import { System
} from '@serpentity/serpentity';
3 import PhysicalWithAttributesNode
from '../nodes/physical_with_attributes';
6 * Distribuets physics data to the related components
8 * @extends {external:Serpentity.System}
9 * @class PhysicsToAttributesSystem
10 * @param {object} config a configuration object to extend.
12 export default class PhysicsToAttributesSystem
extends System
{
14 constructor(config
= {}) {
19 * The node collection of physics entities
21 * @property {external:Serpentity.NodeCollection} physicalEntities
23 * @memberof PhysicsToAttributesSystem
25 this.physicalEntities
= null;
29 * Initializes system when added. Requests physics nodes
32 * @memberof PhysicsToAttributesSystem
34 * @param {external:Serpentity.Engine} engine the serpentity engine to
35 * which we are getting added
39 this.physicalEntities
= engine
.getNodes(PhysicalWithAttributesNode
);
43 * Clears system resources when removed.
47 * @memberof PhysicsToAttributesSystem
51 this.physicalEntities
= null;
55 * Runs on every update of the loop. Updates the other components
60 * @param {Number} currentFrameDuration the duration of the current
62 * @memberof PhysicsToAttributesSystem
64 update(currentFrameDuration
) {
66 for (const physicalEntity
of this.physicalEntities
) {
67 physicalEntity
.position
.x
= physicalEntity
.body
.body
.position
.x
;
68 physicalEntity
.position
.y
= physicalEntity
.body
.body
.position
.y
;
69 physicalEntity
.angle
.angle
= physicalEntity
.body
.body
.angle
;