multi touch / swipe (very buggy)

This commit is contained in:
Cameron Taylor 2021-08-25 13:18:45 -04:00
parent 27da6fdba9
commit 84a2b980a5

View file

@ -852,6 +852,14 @@ typedef SaveInputLists =
?pad:Array<Int> ?pad:Array<Int>
}; };
typedef Swipes =
{
?initTouchPos:FlxPoint,
?touchAngle:Float,
?touchLength:Float,
?curTouchPos:FlxPoint
};
class FlxActionInputDigitalMobileSwipeGameplay extends FlxActionInputDigital class FlxActionInputDigitalMobileSwipeGameplay extends FlxActionInputDigital
{ {
public function new(swipeDir:Int = FlxObject.ANY, Trigger:FlxInputState) public function new(swipeDir:Int = FlxObject.ANY, Trigger:FlxInputState)
@ -859,9 +867,10 @@ class FlxActionInputDigitalMobileSwipeGameplay extends FlxActionInputDigital
super(MOBILE, swipeDir, Trigger); super(MOBILE, swipeDir, Trigger);
} }
// multiple swipe support // fix right swipe
// make datatype that has all 3 needed info and then make an array of them? // fix down swipe on left side of screen?
// var touchMap:Map<Int, Swipes> = new Map();
var initTouchPos:FlxPoint = new FlxPoint(); var initTouchPos:FlxPoint = new FlxPoint();
var touchAngle:Float = 0; var touchAngle:Float = 0;
@ -882,30 +891,47 @@ class FlxActionInputDigitalMobileSwipeGameplay extends FlxActionInputDigital
{ {
if (touch.justPressed) if (touch.justPressed)
{ {
initTouchPos.set(touch.screenX, touch.screenY); var pos:FlxPoint = new FlxPoint(touch.screenX, touch.screenY);
var pos2:FlxPoint = new FlxPoint(touch.screenX, touch.screenY);
var swp:Swipes = {
initTouchPos: pos,
curTouchPos: pos2,
touchAngle: 0,
touchLength: 0
};
touchMap[touch.touchPointID] = swp;
curStep = 1; curStep = 1;
Haptic.vibrate(40, 70); Haptic.vibrate(40, 70);
} }
if (touch.pressed) if (touch.pressed)
{ {
curTouchPos.set(touch.screenX, touch.screenY); var daSwipe = touchMap[touch.touchPointID];
var dx = initTouchPos.x - touch.screenX; daSwipe.curTouchPos.set(touch.screenX, touch.screenY);
var dy = initTouchPos.y - touch.screenY;
touchAngle = Math.atan2(dy, dx); var dx = daSwipe.initTouchPos.x - touch.screenX;
touchLength = Math.sqrt(dx * dx + dy * dy); var dy = daSwipe.initTouchPos.y - touch.screenY;
FlxG.watch.addQuick("LENGTH", touchLength); daSwipe.touchAngle = Math.atan2(dy, dx);
FlxG.watch.addQuick("ANGLE", FlxAngle.asDegrees(touchLength)); daSwipe.touchLength = Math.sqrt(dx * dx + dy * dy);
if (touchLength >= (activateLength / vibrationSteps) * curStep) // FlxG.watch.addQuick("LENGTH", touchLength);
// FlxG.watch.addQuick("ANGLE", FlxAngle.asDegrees(touchLength));
if (daSwipe.touchLength >= (activateLength / vibrationSteps) * curStep)
{ {
curStep += 1; curStep += 1;
// Haptic.vibrate(Std.int(hapticPressure / (curStep * 1.5)), 50); // Haptic.vibrate(Std.int(hapticPressure / (curStep * 1.5)), 50);
} }
} }
if (touch.justReleased)
{
touchMap.remove(touch.touchPointID);
}
/* switch (inputID) /* switch (inputID)
{ {
case FlxObject.UP: case FlxObject.UP:
@ -919,36 +945,39 @@ class FlxActionInputDigitalMobileSwipeGameplay extends FlxActionInputDigital
override public function check(Action:FlxAction):Bool override public function check(Action:FlxAction):Bool
{ {
var degAngle = FlxAngle.asDegrees(touchAngle); for (swp in touchMap)
switch (trigger)
{ {
case JUST_PRESSED: var degAngle = FlxAngle.asDegrees(swp.touchAngle);
if (touchLength >= activateLength) // 90 is random ass value lol
{ switch (trigger)
switch (inputID) {
case JUST_PRESSED:
if (swp.touchLength >= activateLength) // 90 is random ass value lol
{ {
case FlxObject.UP: switch (inputID)
if (degAngle >= 45 && degAngle <= 90 + 45) return properTouch(); {
case FlxObject.DOWN: case FlxObject.UP:
if (-degAngle >= 45 && -degAngle <= 90 + 45) return properTouch(); if (degAngle >= 45 && degAngle <= 90 + 45) return properTouch(swp);
case FlxObject.LEFT: case FlxObject.DOWN:
if (degAngle <= 45 && -degAngle <= 45) return properTouch(); if (-degAngle >= 45 && -degAngle <= 90 + 45) return properTouch(swp);
case FlxObject.RIGHT: case FlxObject.LEFT:
if (degAngle >= 90 + 45 && -degAngle >= 90 + 45) return properTouch(); if (degAngle <= 45 && -degAngle <= 45) return properTouch(swp);
case FlxObject.RIGHT:
if (degAngle >= 90 + 45 && -degAngle >= 90 + 45) return properTouch(swp);
}
} }
} default:
default: }
} }
return false; return false;
} }
function properTouch():Bool function properTouch(swipe:Swipes):Bool
{ {
curStep = 1; curStep = 1;
Haptic.vibrate(100, 30); Haptic.vibrate(100, 30);
initTouchPos.set(curTouchPos.x, curTouchPos.y); swipe.initTouchPos.set(curTouchPos.x, curTouchPos.y);
return true; return true;
} }
} }