Browse Source

Touch input

Josh Engebretson 10 years ago
parent
commit
5ee3296b49

+ 14 - 45
RoboMan3D/Resources/Components/AvatarController.js

@@ -184,55 +184,24 @@ function UpdateControls() {
     // Mouse sensitivity as degrees per pixel
     var MOUSE_SENSITIVITY = 0.1;
 
-    if (input.getNumJoysticks()) {
-        var state = GetGamepadState(0);
-        if (state.axis0 < -0.5)
-            moveLeft = true;
-        if (state.axis0 > 0.5)
-            moveRight = true;
-        if (state.axis1 < -0.5)
-            moveForward = true;
-        if (state.axis1 > 0.5)
-            moveBackwards = true;
-
-        if (state.button0 && !lastButton0) {
-            button0 = true;
-            lastButton0 = true;
-        } else if (!state.button0) {
-            lastButton0 = false;
-        }
-
-        if (state.button1 && !lastButton1) {
-            button1 = true;
-            lastButton1 = true;
-        } else if (!state.button1) {
-            lastButton1 = false;
-        }
-
-        mouseMoveX = state.axis2 * 20;
-        mouseMoveY = state.axis3 * 10;
+    if (input.getKeyDown(Atomic.KEY_W))
+        moveForward = true;
+    if (input.getKeyDown(Atomic.KEY_S))
+        moveBackwards = true;
+    if (input.getKeyDown(Atomic.KEY_A))
+        moveLeft = true;
+    if (input.getKeyDown(Atomic.KEY_D))
+        moveRight = true;
 
-    } else {
+    if (input.getKeyPress(Atomic.KEY_F))
+        button0 = true;
+    if (input.getKeyPress(Atomic.KEY_SPACE))
+        button1 = true;
 
-        if (input.getKeyDown(Atomic.KEY_W))
-            moveForward = true;
-        if (input.getKeyDown(Atomic.KEY_S))
-            moveBackwards = true;
-        if (input.getKeyDown(Atomic.KEY_A))
-            moveLeft = true;
-        if (input.getKeyDown(Atomic.KEY_D))
-            moveRight = true;
+    mouseMoveX = input.getMouseMoveX();
+    mouseMoveY = input.getMouseMoveY();
 
-        if (input.getKeyPress(Atomic.KEY_F))
-            button0 = true;
-        if (input.getKeyPress(Atomic.KEY_SPACE))
-            button1 = true;
 
-        mouseMoveX = input.getMouseMoveX();
-        mouseMoveY = input.getMouseMoveY();
-
-
-    }
 
 }
 

+ 19 - 0
RoboMan3D/Resources/Components/TouchInput.js

@@ -0,0 +1,19 @@
+
+// Atomic Component
+
+var game = Atomic.game;
+var node = self.node;
+var input = game.input;
+
+function start() {
+
+	// input.setTouchEmulation(true);
+    var layout = game.cache.getResource("XMLFile", "Data/ScreenJoystick.xml");
+    var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");    
+    input.addScreenJoystick(layout, uiStyle);
+
+}
+
+function update(timeStep) {
+
+}

+ 28 - 0
RoboMan3D/Resources/Data/ScreenJoystick.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<element inherit="UI/ScreenJoystick.xml">
+    <replace sel="/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value">Jump</replace>
+    <add sel="/element/element[./attribute[@name='Name' and @value='Button0']]">
+        <attribute name="Is Visible" value="true" />
+        <element type="Text">
+        <attribute name="Name" value="KeyBinding" />
+        <attribute name="Text" value="SPACE" />
+        </element>
+    </add>
+    <add sel="/element/element[./attribute[@name='Name' and @value='Button1']]">
+        <attribute name="Is Visible" value="false" />
+    </add>
+    <add sel="/element/element[./attribute[@name='Name' and @value='Button2']]">
+        <element type="Text">
+            <attribute name="Name" value="KeyBinding" />
+            <attribute name="Text" value="SELECT" />
+        </element>
+    </add>
+    <replace sel="/element/element[./attribute[@name='Name' and @value='Hat0']]/attribute[@name='Position']/@value">12 -76</replace>
+    <add sel="/element/element[./attribute[@name='Name' and @value='Hat0']]">
+        <attribute name="Is Visible" value="true" />
+        <element type="Text">
+            <attribute name="Name" value="KeyBinding" />
+            <attribute name="Text" value="WSAD" />
+                    </element>
+    </add>
+</element>

+ 4 - 0
RoboMan3D/Resources/Scripts/main.js

@@ -17,6 +17,10 @@ function start() {
 	// create the game component
 	var node = game.scene.createChild("TheScene");
 	node.createJSComponent("Scene");
+	
+    if (Atomic.platform == "iOS" || Atomic.platform == "Android")
+	    node.createJSComponent("TouchInput");
+	
 
 }