main.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. var DPad_1 = require("DPad");
  3. // called per frame, optional
  4. function update(timeStep) {
  5. // Handle update
  6. }
  7. exports.update = update;
  8. // This script is the main entry point of the game
  9. //Load scene
  10. Atomic.player.loadScene("Scenes/Test.scene");
  11. //init DPad if its a mobile platform
  12. if (Atomic.platform == "Android" || Atomic.platform == "iOS") {
  13. var dpad = new DPad_1.DPad();
  14. dpad.addAll();
  15. dpad.init();
  16. var jumpView = new Atomic.UIView();
  17. var jumpButton = new Atomic.UIButton();
  18. //unset its skin, because we will use UIImageWidget
  19. jumpButton.skinBg = "";
  20. //create ours jump button image
  21. var jumpButtonImage = new Atomic.UIImageWidget();
  22. //load image
  23. jumpButtonImage.setImage("UI/jumpButton.png");
  24. //resize ours image by 2.2x
  25. var jumpButtonWidth = jumpButtonImage.imageWidth * 2.2;
  26. var jumpButtonHeight = jumpButtonImage.imageHeight * 2.2;
  27. //calculate position
  28. var posX = Atomic.graphics.width - Atomic.graphics.width / 8 - jumpButtonWidth / 2;
  29. var posY = Atomic.graphics.height - Atomic.graphics.height / 4 - jumpButtonHeight / 2;
  30. //sets jumpButton rect, specify position and end position
  31. jumpView.rect = [posX, posY, posX + jumpButtonWidth, posY + jumpButtonHeight];
  32. jumpButton.rect = [0, 0, jumpButtonWidth, jumpButtonHeight];
  33. //sets jumpButtonImage rect, we specify there only end position
  34. jumpButtonImage.rect = [0, 0, jumpButtonWidth, jumpButtonHeight];
  35. //adds image to jumpButton
  36. jumpButton.addChild(jumpButtonImage);
  37. //adds jumpButton to the dpad view
  38. jumpView.addChild(jumpButton);
  39. //sets jumpButton capturing to false, because we wanna make it multitouchable
  40. jumpButton.setCapturing(false);
  41. //binds jumpButton to KEY_SPACE
  42. Atomic.input.bindButton(jumpButton, Atomic.KEY_SPACE);
  43. }