Light.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.softShadowLength = 4;
  7. light.castShadows = true;
  8. light.softShadows = true;
  9. light.numRays = 512;
  10. Light2DExample.lightGroup.addLight(light);
  11. var x = -Light2DExample.halfWidth + (Light2DExample.halfWidth * 2) * Math.random();
  12. var y = -Light2DExample.halfHeight + (Light2DExample.halfHeight * 2) * Math.random();
  13. node.position2D = [x, y];
  14. var movex = -2 + (Math.random() * 4);
  15. var movey = -2 + (Math.random() * 4);
  16. function start() {
  17. }
  18. function update(timeStep) {
  19. var prev = node.position2D;
  20. node.translate2D([movex * timeStep, movey * timeStep]);
  21. var p = node.position2D;
  22. if (p[0] < -Light2DExample.halfWidth || p[0] > Light2DExample.halfWidth) {
  23. node.position2D = prev;
  24. movex = -movex;
  25. }
  26. if (p[1] < -Light2DExample.halfHeight || p[1] > Light2DExample.halfHeight) {
  27. node.position2D = prev;
  28. movey = -movey;
  29. }
  30. }