main.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // This script is the main entry point of the game
  2. //Load scene
  3. Atomic.player.loadScene("Scenes/Test.scene");
  4. Atomic.input.setMouseVisible(false);
  5. exports.update = function() {
  6. if (Atomic.input.getKeyDown(Atomic.KEY_ESCAPE)) {
  7. Atomic.engine.exit();
  8. }
  9. }
  10. //init DPad if its a mobile platform
  11. if(Atomic.platform == "Android" || Atomic.platform == "iOS") {
  12. var DPad = require("DPad");
  13. var dpad = new 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. }