main.ts 1.8 KB

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