HUD.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var game = Atomic.game;
  2. var ui = game.ui;
  3. var root = ui.getRoot();
  4. var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  5. root.defaultStyle = uiStyle;
  6. var scoreText = new Atomic.Text();
  7. scoreText.text = "Score: 0";
  8. var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
  9. scoreText.setFont(font, 24);
  10. scoreText.color = [0, 1, 0, 1];
  11. scoreText.horizontalAlignment = Atomic.HA_RIGHT;
  12. scoreText.verticalAlignment = Atomic.VA_TOP;
  13. root.addChild(scoreText);
  14. var titleText = new Atomic.Text();
  15. titleText.text = "Atomic Space Game";
  16. titleText.setFont(font, 18);
  17. titleText.color = [0, 1, 0, 1];
  18. titleText.horizontalAlignment = Atomic.HA_LEFT;
  19. titleText.verticalAlignment = Atomic.VA_TOP;
  20. root.addChild(titleText);
  21. var healthText = new Atomic.Text();
  22. healthText.text = "Health: 10";
  23. healthText.setFont(font, 18);
  24. healthText.color = [0, 1, 0, 1];
  25. healthText.horizontalAlignment = Atomic.HA_RIGHT;
  26. healthText.verticalAlignment = Atomic.VA_BOTTOM;
  27. root.addChild(healthText);
  28. var gameText = new Atomic.Text();
  29. gameText.setFont(font, 40);
  30. gameText.color = [0, 1, 0, 1];
  31. gameText.horizontalAlignment = Atomic.HA_CENTER;
  32. gameText.verticalAlignment = Atomic.VA_CENTER;
  33. root.addChild(gameText);
  34. if (Atomic.platform == "iOS" || Atomic.platform == "Android")
  35. self.node.createJSComponent("TouchInput");
  36. self.updateScore = function (value) {
  37. scoreText.text = "Score: " + value;
  38. }
  39. self.updateHealth = function (value) {
  40. healthText.text = "Health: " + value;
  41. }
  42. self.updateGameText = function (text) {
  43. gameText.text = text;
  44. }
  45. function start() {
  46. }
  47. function update(timeStep) {
  48. }