Main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var game = Atomic.game
  2. cache = game.cache;
  3. graphics = game.graphics;
  4. renderer = game.renderer;
  5. engine = game.engine;
  6. input = game.input;
  7. var halfWidth = graphics.width * Atomic.PIXEL_SIZE * 0.5;
  8. var halfHeight = graphics.height * Atomic.PIXEL_SIZE * 0.5;
  9. var enableDebugHud = false;
  10. function Start() {
  11. if (enableDebugHud) {
  12. var uiStyle = cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  13. var debugHud = engine.createDebugHud();
  14. debugHud.defaultStyle = uiStyle;
  15. debugHud.toggleAll();
  16. }
  17. CreateScene();
  18. }
  19. function Update() {
  20. //physicsWorld.drawDebugGeometry();
  21. }
  22. function CreateScene() {
  23. daytime = false;
  24. game.createScene2D();
  25. scene = game.scene;
  26. cameraNode = game.cameraNode;
  27. camera = game.camera;
  28. physicsWorld = scene.createComponent("PhysicsWorld2D");
  29. physicsWorld.continuousPhysics = false;
  30. physicsWorld.subStepping = false;
  31. // currently lightgroup must be created after viewport 0 is set
  32. lightGroupNode = scene.createChild("LightGroup");
  33. lightGroup = lightGroupNode.createComponent("Light2DGroup");
  34. lightGroup.setPhysicsWorld(physicsWorld);
  35. if (daytime)
  36. lightGroup.ambientColor = [1, 1, 1, 1];
  37. else
  38. lightGroup.ambientColor = [.8, .8, .8, .25];
  39. if (daytime)
  40. {
  41. TheSun = scene.createComponent("DirectionalLight2D");
  42. TheSun.color = [1, 1, 1, 0.15];
  43. TheSun.castShadows = true;
  44. TheSun.numRays = 1024;
  45. TheSun.backtrace = false;
  46. lightGroup.addLight(TheSun);
  47. }
  48. //uiNode = scene.createChild("UI");
  49. //uiNode.createJSComponent("UI");
  50. levelNode = scene.createChild("Level");
  51. levelNode.createJSComponent("Level");
  52. avatarNode = scene.createChild("Avatar");
  53. avatarNode.createJSComponent("Avatar");
  54. backgroundNode = scene.createChild("Background");
  55. backgroundNode .createJSComponent("Background");
  56. }