Light.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var game = Atomic.game;
  2. var node = self.node;
  3. var light = node.createComponent("PointLight2D");
  4. light.color = [.1 + Math.random() * .9, .1 + Math.random() * .9, .1 + Math.random() * .9, 1];
  5. light.radius = 4;
  6. light.castShadows = true;
  7. light.softShadows = true;
  8. light.numRays = 512;
  9. Light2DExample.lightGroup.addLight(light);
  10. var x = -Light2DExample.halfWidth + (Light2DExample.halfWidth * 2) * Math.random();
  11. var y = -Light2DExample.halfHeight + (Light2DExample.halfHeight * 2) * Math.random();
  12. node.position2D = [x, y];
  13. var movex = -2 + (Math.random() * 4);
  14. var movey = -2 + (Math.random() * 4);
  15. function start() {
  16. }
  17. function update(timeStep) {
  18. var prev = node.position2D;
  19. node.translate2D([movex * timeStep, movey * timeStep]);
  20. var p = node.position2D;
  21. if (p[0] < -Light2DExample.halfWidth || p[0] > Light2DExample.halfWidth) {
  22. node.position2D = prev;
  23. movex = -movex;
  24. }
  25. if (p[1] < -Light2DExample.halfHeight || p[1] > Light2DExample.halfHeight) {
  26. node.position2D = prev;
  27. movey = -movey;
  28. }
  29. }