main.js 1.6 KB

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