v2.0.1: buttons no longer retain presses when deactivated
This commit is contained in:
@@ -141,6 +141,8 @@ public class Button extends Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float lastUpdateTime = Float.POSITIVE_INFINITY;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
@@ -148,7 +150,19 @@ public class Button extends Component {
|
|||||||
hotArea.active = visible;
|
hotArea.active = visible;
|
||||||
|
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
if ((pressTime += Game.elapsed) >= longClick) {
|
//if this button hasn't updated for a bit while held, it was probably deactivated.
|
||||||
|
// cancel the hold action in these cases.
|
||||||
|
if (Game.timeTotal - 0.5f >= lastUpdateTime){
|
||||||
|
hotArea.reset();
|
||||||
|
pressed = false;
|
||||||
|
onPointerUp();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
lastUpdateTime = Game.timeTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pressed && (pressTime += Game.elapsed) >= longClick) {
|
||||||
pressed = false;
|
pressed = false;
|
||||||
if (onLongClick()) {
|
if (onLongClick()) {
|
||||||
|
|
||||||
@@ -159,6 +173,8 @@ public class Button extends Component {
|
|||||||
Game.vibrate( 50 );
|
Game.vibrate( 50 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
lastUpdateTime = Float.POSITIVE_INFINITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user