main.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This script is the main entry point of the game
  2. // create a scene
  3. var scene = new Atomic.Scene();
  4. // assign scene into global so it's not GC'd
  5. Atomic.Player.currentScene = scene;
  6. // create an octree component
  7. scene.createComponent("Octree");
  8. // create out camera
  9. var cameraNode = scene.createChild("Camera");
  10. var camera = cameraNode.createComponent("Camera");
  11. // setup as 2D
  12. camera.setOrthographic(true);
  13. //Atomic.PIXEL_SIZE / 2 means that our pixels are doubled up
  14. camera.setOrthoSize(Atomic.graphics.height * Atomic.PIXEL_SIZE / 2);
  15. // create a viewport
  16. var viewport = new Atomic.Viewport(scene, camera);
  17. Atomic.renderer.setViewport(0, viewport);
  18. // create our spawner component
  19. scene.createJSComponent("Components/Spawner.js");
  20. createInstructions();
  21. function createInstructions() {
  22. var view = new Atomic.UIView();
  23. // Create a layout, otherwise child widgets won't know how to size themselves
  24. // and would manually need to be sized
  25. var layout = new Atomic.UILayout();
  26. // specify the layout region
  27. layout.rect = view.rect;
  28. view.addChild(layout);
  29. // we're laying out on the X axis so "position" controls top and bottom alignment
  30. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_RIGHT_BOTTOM;
  31. // while "distribution" handles the Y axis
  32. layout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM;
  33. var fd = new Atomic.UIFontDescription();
  34. fd.id = "Vera";
  35. fd.size = 18;
  36. var scoreText = new Atomic.UIEditField();
  37. scoreText.fontDescription = fd;
  38. scoreText.readOnly = true;
  39. scoreText.multiline = true;
  40. scoreText.adaptToContentSize = true;
  41. scoreText.text = "Atomic Butterflies\nLeft Mouse - Spawn Butterflies\nRight Click - Spawn Particles";
  42. layout.addChild(scoreText);
  43. }