main.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This script is the main entry point of the game
  2. Light2DExample = {};
  3. // called at the start of play
  4. function Start() {
  5. var game = Atomic.game;
  6. Light2DExample.halfWidth = game.graphics.width * Atomic.PIXEL_SIZE * 0.5;
  7. Light2DExample.halfHeight = game.graphics.height * Atomic.PIXEL_SIZE * 0.5;
  8. // create a 2D scene
  9. game.createScene2D();
  10. var scene = game.scene;
  11. var physicsWorld = scene.createComponent("PhysicsWorld2D");
  12. physicsWorld.continuousPhysics = false;
  13. physicsWorld.subStepping = false;
  14. var lightGroupNode = scene.createChild("LightGroup");
  15. var lightGroup = lightGroupNode.createComponent("Light2DGroup");
  16. lightGroup.setPhysicsWorld(physicsWorld);
  17. lightGroup.ambientColor = [.8, .8, .8, .5];
  18. Light2DExample.lightGroup = lightGroup;
  19. var node = game.scene.createChild();
  20. node.createJSComponent("Background");
  21. node.createJSComponent("Physics");
  22. for (var i = 0; i < 4; i++) {
  23. var lightNode = scene.createChild("LightNode");
  24. lightNode.createJSComponent("Light");
  25. }
  26. for (var i = 0; i < 16; i++) {
  27. var shadowCasterNode = scene.createChild("ShadowCaster");
  28. shadowCasterNode.createJSComponent("ShadowCaster");
  29. }
  30. }
  31. // called per frame
  32. function Update(timeStep) {
  33. physicsWorld.drawDebugGeometry();
  34. }