Background.js 865 B

12345678910111213141516171819202122232425
  1. "atomic component";
  2. //A Background
  3. var component = function(self) {
  4. //getting a main camera of current scene
  5. var camera = self.node.scene.getMainCamera();
  6. var cameraNode = camera.node;
  7. //This function will be called each frame after the update function
  8. self.postUpdate = function() {
  9. //get position of our camera
  10. //position2D returns an array, which has 3 elements, the first is x, second is y, third is z
  11. var pos = cameraNode.position2D;
  12. pos[1] -= 4;
  13. //set position to the current node
  14. self.node.position2D = pos;
  15. //get camera's zoom, and changing it to make a nice paralax effect
  16. var zoom = 4.0 - camera.zoom;
  17. //scale2D is an array with two elements, the first is x, the second is y
  18. self.node.scale2D = [zoom , zoom];
  19. };
  20. };
  21. exports.component = component;