Wall.js 880 B

1234567891011121314151617181920212223
  1. "atomic component";
  2. //A Wall component
  3. exports.component = function(self) {
  4. self.start = function() {
  5. //get rigid body component
  6. self.rigidBody = self.node.getComponent("RigidBody2D");
  7. //create a new chain to define a wall
  8. var chain = self.node.createComponent("CollisionChain2D");
  9. chain.loop = false;
  10. //set vertex cound to 4
  11. chain.setVertexCount(4);
  12. var zoom = self.node.scene.getMainCamera().zoom;
  13. var halfWidth = Atomic.graphics.width / 2 * Atomic.PIXEL_SIZE / zoom;
  14. var halfHeight = Atomic.graphics.height / 2 * Atomic.PIXEL_SIZE / zoom;
  15. //define vertexes
  16. chain.setVertex(0, [-halfWidth, -halfHeight]);
  17. chain.setVertex(1, [-halfWidth, halfHeight]);
  18. chain.setVertex(2, [halfWidth, halfHeight]);
  19. chain.setVertex(3, [halfWidth, -halfHeight]);
  20. };
  21. };