Ver código fonte

Added jumpButton.

rsredsq 10 anos atrás
pai
commit
e8af310f92

+ 5 - 3
PhysicsPlatformer/Resources/Modules/DPad.js

@@ -13,14 +13,16 @@ function DPad() {
       //if  touch buttons skin is not loaded
       if(!DPad.skinLoaded) {
         //load skin
-        Atomic.ui.loadSkin("Ui/touchButtonsSkin.ui");
+        Atomic.ui.loadSkin("UI/DPadSkin.ui");
         DPad.skinLoaded = true;
       }
-      //sets its position by default
-      this.view.setPosition(-width/8, height/10);
       //create a dpad layout
       this.dpad = new Atomic.UILayout();
       this.dpad.rect = this.view.rect;
+      //sets dpad position
+      this.dpad.setPosition(-width/4, height/10);
+      //move buttons a bit closer to each other
+      this.dpad.spacing = -30;
       //if layouts are exists, add them
       if(this.leftLayout)
         this.dpad.addChild(this.leftLayout);

+ 27 - 0
PhysicsPlatformer/Resources/Scripts/main.js

@@ -71,5 +71,32 @@ function run(daytime) {
     dpad.addAll();
     //ok, then we could init ours dpad
     dpad.init();
+    //create a jump button
+    var jumpButton = new Atomic.UIButton();
+    //unset its skin, because we will use UIImageWidget
+    jumpButton.skinBg = "";
+    //create ours jump button image
+    var jumpButtonImage = new Atomic.UIImageWidget();
+    //load image
+    jumpButtonImage.setImage("UI/jumpButton.png");
+    //resize ours image by 2x
+    var jumpButtonWidth = jumpButtonImage.imageWidth*2;
+    var jumpButtonHeight = jumpButtonImage.imageHeight*2;
+    //calculate position
+    var posX = Atomic.graphics.width - Atomic.graphics.width/6;
+    var posY = Atomic.graphics.height - Atomic.graphics.height/2.5;
+
+    //sets jumpButton rect, specify position and end position
+    jumpButton.rect = [posX, posY, posX+jumpButtonWidth, posY+jumpButtonHeight];
+    //sets jumpButtonImage rect, we specify there only end position
+    jumpButtonImage.rect = [0, 0, jumpButtonWidth, jumpButtonHeight];
+    //adds image to jumpButton
+    jumpButton.addChild(jumpButtonImage);
+    //adds jumpButton to the dpad view
+    dpad.view.addChild(jumpButton);
+    //sets jumpButton capturing to false, because we wanna make it multitouchable
+    jumpButton.setCapturing(false);
+    //binds jumpButton to KEY_SPACE
+    Atomic.input.bindButton(jumpButton, Atomic.KEY_SPACE);
   }
 }

+ 0 - 0
PhysicsPlatformer/Resources/Ui/touchButtonsSkin.ui → PhysicsPlatformer/Resources/Ui/DPadSkin.ui


BIN
PhysicsPlatformer/Resources/Ui/jumpButton.png


+ 0 - 6
PhysicsPlatformer/Resources/Ui/touchButtonsUI.ui

@@ -1,6 +0,0 @@
-TBLayout: axis: y, distribution: gravity
-	TBContainer: gravity: all
-		TBButton: text: Left, gravity: left top bottom, id: left
-		TBButton: text: Right, gravity: right top bottom, id: right
-		TBButton: text: Up, gravity: top left right, id: up
-		TBButton: text: Down, gravity: bottom left right, id: down