AtomicGame.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. Atomic.editor = null;
  2. function Game() {
  3. this.engine = Atomic.getEngine();
  4. this.cache = Atomic.getResourceCache();
  5. this.renderer = Atomic.getRenderer();
  6. this.graphics = Atomic.getGraphics();
  7. this.input = Atomic.getInput();
  8. this.ui = Atomic.getUI();
  9. this.input.setMouseVisible(true);
  10. if (Atomic.platform == "Android") {
  11. this.renderer.reuseShadowMaps = false;
  12. this.renderer.shadowQuality = Atomic.SHADOWQUALITY_LOW_16BIT;
  13. }
  14. }
  15. Game.prototype.init = function(start, update) {
  16. this.update = update;
  17. // register global to get at quickly
  18. __js_atomicgame_update = update;
  19. if (typeof(start) === "function")
  20. start();
  21. }
  22. Game.prototype.getSpriteSheet2D = function(xmlFile) {
  23. return this.cache.getResource("SpriteSheet2D", xmlFile);
  24. }
  25. Game.prototype.getSpriteSheet = Game.prototype.getSpriteSheet2D;
  26. Game.prototype.getSound = function(soundFile) {
  27. return this.cache.getResource("Sound", soundFile);
  28. }
  29. Game.prototype.getSprite2D = function(spriteFile) {
  30. return this.cache.getResource("Sprite2D", spriteFile);
  31. }
  32. Game.prototype.showDebugHud = function() {
  33. var uiStyle = this.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  34. var debugHud = this.engine.createDebugHud();
  35. debugHud.defaultStyle = uiStyle;
  36. debugHud.toggleAll();
  37. }
  38. Game.prototype.createScene2D = function() {
  39. var scene = new Atomic.Scene();
  40. scene.createComponent("Octree");
  41. var cameraNode = scene.createChild("Camera");
  42. cameraNode.position = [0.0, 0.0, -10.0];
  43. var camera = cameraNode.createComponent("Camera");
  44. camera.orthographic = true;
  45. camera.orthoSize = this.graphics.height * Atomic.PIXEL_SIZE;
  46. var viewport = null;
  47. if (Atomic.editor) {
  48. viewport = Atomic.editor.setView(scene, camera);
  49. } else {
  50. viewport = new Atomic.Viewport(scene, camera);
  51. this.renderer.setViewport(0, viewport);
  52. }
  53. this.scene = scene;
  54. this.cameraNode = cameraNode;
  55. this.camera = camera;
  56. this.viewport = viewport;
  57. return scene;
  58. }
  59. Game.prototype.createScene3D = function(filename) {
  60. var scene = new Atomic.Scene();
  61. if (typeof(filename) == "string")
  62. scene.loadXML(filename)
  63. else
  64. scene.createComponent("Octree");
  65. var cameraNode = scene.createChild("Camera");
  66. cameraNode.position = [0.0, 0.0, -10.0];
  67. var camera = cameraNode.createComponent("Camera");
  68. var viewport = null;
  69. if (Atomic.editor) {
  70. viewport = Atomic.editor.setView(scene, camera);
  71. } else {
  72. viewport = new Atomic.Viewport(scene, camera);
  73. this.renderer.setViewport(0, viewport);
  74. }
  75. this.scene = scene;
  76. this.cameraNode = cameraNode;
  77. this.camera = camera;
  78. this.viewport = viewport;
  79. return scene;
  80. }
  81. Atomic.game = exports.game = new Game();