Ok, so I’ve been working on a D-pad and a button divided by two sides of the screen. On one of my test devices the touch on the button side of the screen interferes with the D-pad side of the screen. This happens when the user places both fingers in the two zones and then releases one. However, on my other test device it runs perfectly fine. HTC one s is having the issue and nexus 7 fhd is not. Is it just older versions on android that don’t like the style of multi touch detection? I will post the code shortly as I am not at my computer. Any advice would be awesome.
private var PlayerObject : GameObject;
private var MidPoint : Vector2;
private var DPadSize : float;
private var Origin : Vector2;
private var DPadRay : float;
private var TRAncor : Vector2;
private var TLAncor : Vector2;
private var BRAncor : Vector2;
private var BLAncor : Vector2;
private var LT : Vector2;
private var LB : Vector2;
private var TL : Vector2;
private var TR : Vector2;
private var RT : Vector2;
private var RB : Vector2;
private var BL : Vector2;
private var BR : Vector2;
var DPadHorizontal : GUITexture;
var DPadVertical : GUITexture;
var DPadOnRight : GUITexture;
var DPadOnUp : GUITexture;
var DPadOnLeft : GUITexture;
var DPadOnDown : GUITexture;
private var DPadID : int = -1;
private var FireID : int = -1;
function Start(){
PlayerObject = GameObject.FindGameObjectWithTag(“Player”);
MidPoint = Vector2(Screen.width / 2,Screen.height / 2);
DPadSize = Screen.width / 30;
DPadRay = (DPadSize * 3);
Origin = Vector2(Screen.width / 8, Screen.width / 8);
//=================================================================//
//D-Pad Creation//
TRAncor = Vector2(Origin.x + DPadSize,Origin.y + DPadSize);
TLAncor = Vector2(Origin.x - DPadSize,Origin.y + DPadSize);
BRAncor = Vector2(Origin.x + DPadSize,Origin.y - DPadSize);
BLAncor = Vector2(Origin.x - DPadSize,Origin.y - DPadSize);
LT = Vector2(Origin.x - DPadRay, Origin.y + DPadSize);
LB = Vector2(Origin.x - DPadRay, Origin.y - DPadSize);
TL = Vector2(Origin.x - DPadSize, Origin.y + DPadRay);
TR = Vector2(Origin.x + DPadSize, Origin.y + DPadRay);
RT = Vector2(Origin.x + DPadRay, Origin.y + DPadSize);
RB = Vector2(Origin.x + DPadRay, Origin.y - DPadSize);
BL = Vector2(Origin.x - DPadSize, Origin.y - DPadRay);
BR = Vector2(Origin.x + DPadSize, Origin.y - DPadRay);
DPadVertical.pixelInset.width = (TRAncor.x - TLAncor.x);
DPadVertical.pixelInset.height = (TR.y - BL.y);
DPadVertical.pixelInset.x = BL.x;
DPadVertical.pixelInset.y = BR.y;
DPadHorizontal.pixelInset.width = (TR.y - BL.y);
DPadHorizontal.pixelInset.height = (TRAncor.x - TLAncor.x);
DPadHorizontal.pixelInset.x = LB.x;
DPadHorizontal.pixelInset.y = LB.y;
DPadOnRight.pixelInset.width = (TR.y - BL.y);
DPadOnRight.pixelInset.height = (TRAncor.x - TLAncor.x);
DPadOnRight.pixelInset.x = LB.x;
DPadOnRight.pixelInset.y = LB.y;
DPadOnUp.pixelInset.width = (TRAncor.x - TLAncor.x);
DPadOnUp.pixelInset.height = (TR.y - BL.y);
DPadOnUp.pixelInset.x = BL.x;
DPadOnUp.pixelInset.y = BL.y;
DPadOnLeft.pixelInset.width = (TR.y - BL.y);
DPadOnLeft.pixelInset.height = (TRAncor.x - TLAncor.x);
DPadOnLeft.pixelInset.x = LB.x;
DPadOnLeft.pixelInset.y = LB.y;
DPadOnDown.pixelInset.width = (TRAncor.x - TLAncor.x);
DPadOnDown.pixelInset.height = (TR.y - BL.y);
DPadOnDown.pixelInset.x = BL.x;
DPadOnDown.pixelInset.y = BL.y;
//=================================================================//
}
function Update(){
for(var touch : Touch in Input.touches){
if(touch.phase == TouchPhase.Began){
if(touch.position.x < MidPoint.x){
DPadID = touch.fingerId;
}
if(touch.position.x > MidPoint.x){
FireID = touch.fingerId;
}
}
if(touch.phase == TouchPhase.Ended /*|| touch.phase == TouchPhase.Canceled*/){
if(touch.fingerId == FireID){
FireID = -1;
}
else if(touch.fingerId == DPadID){
DPadID = -1;
DPadOnUp.enabled = false;
DPadOnDown.enabled = false;
DPadOnLeft.enabled = false;
DPadOnRight.enabled = false;
}
}
if(touch.fingerId == DPadID){
if(Input.GetTouch(DPadID).position.x > TL.x && Input.GetTouch(DPadID).position.x < TR.x && Input.GetTouch(DPadID).position.y > TLAncor.y && Input.GetTouch(DPadID).position.y < TR.y){
PlayerObject.transform.Translate(Vector3.forward * Time.deltaTime * 10);
DPadOnUp.enabled = true;
DPadOnDown.enabled = false;
DPadOnLeft.enabled = false;
DPadOnRight.enabled = false;
}
else if(Input.GetTouch(DPadID).position.x > TRAncor.x && Input.GetTouch(DPadID).position.x < RT.x && Input.GetTouch(DPadID).position.y > BRAncor.y && Input.GetTouch(DPadID).position.y < RT.y){
PlayerObject.transform.Translate(Vector3.right * Time.deltaTime * 10);
DPadOnUp.enabled = false;
DPadOnDown.enabled = false;
DPadOnLeft.enabled = false;
DPadOnRight.enabled = true;
}
else if(Input.GetTouch(DPadID).position.x > BLAncor.x && Input.GetTouch(DPadID).position.x < BR.x && Input.GetTouch(DPadID).position.y > BR.y && Input.GetTouch(DPadID).position.y < BLAncor.y){
PlayerObject.transform.Translate(Vector3.forward * Time.deltaTime * 10 * (-1));
DPadOnUp.enabled = false;
DPadOnDown.enabled = true;
DPadOnLeft.enabled = false;
DPadOnRight.enabled = false;
}
else if(Input.GetTouch(DPadID).position.x > LT.x && Input.GetTouch(DPadID).position.x < TLAncor.x && Input.GetTouch(DPadID).position.y > BLAncor.y && Input.GetTouch(DPadID).position.y < LT.y){
PlayerObject.transform.Translate(Vector3.right * Time.deltaTime * 10 * (-1));
DPadOnUp.enabled = false;
DPadOnDown.enabled = false;
DPadOnLeft.enabled = true;
DPadOnRight.enabled = false;
}
}else{
if(touch.fingerId == FireID){
Debug.Log("fired!");
}
}
}
}