PIXI Controls: Stop idle timer when controls hidden
This commit is contained in:
parent
d833b24e7a
commit
5c7e12c6d0
1 changed files with 22 additions and 6 deletions
|
@ -157,11 +157,12 @@ ONSControls.idleAnimation = function() {
|
|||
// * Check idle animation (spinning buttons)
|
||||
//=============================================================================
|
||||
ONSControls.isIdlePlaying = false;
|
||||
ONSControls.idleDisabled = false;
|
||||
//=============================================================================
|
||||
// * Play idle animation (spinning buttons)
|
||||
//=============================================================================
|
||||
ONSControls.playIdleAnimation = function() {
|
||||
if (!ONSControls.isIdlePlaying) {
|
||||
if (!ONSControls.isIdlePlaying && !ONSControls.idleDisabled) {
|
||||
ONSControls.isIdlePlaying = true;
|
||||
ONSControls._controlsCanvas.ticker.add(ONSControls.idleAnimation);
|
||||
}
|
||||
|
@ -178,6 +179,18 @@ ONSControls.stopIdleAnimation = function() {
|
|||
ONSControls._showButton.rotation = 0;
|
||||
}
|
||||
//=============================================================================
|
||||
// * Reset idle animation timer
|
||||
//=============================================================================
|
||||
ONSControls.resetIdleAnimation = function() {
|
||||
if (ONSControls._idleInterval !== undefined) {
|
||||
ONSControls.stopIdleAnimation();
|
||||
clearInterval(ONSControls._idleInterval);
|
||||
if (!ONSControls.idleDisabled) {
|
||||
ONSControls._idleInterval = setInterval(ONSControls.playIdleAnimation, 300000);
|
||||
}
|
||||
}
|
||||
}
|
||||
//=============================================================================
|
||||
// * Send event to virtual controller
|
||||
//=============================================================================
|
||||
ONSControls.sendEvent = function(event, button) {
|
||||
|
@ -198,8 +211,10 @@ ONSControls.toggle = function(neededState = null) {
|
|||
for (elem of elements) {
|
||||
if (elem.visible || neededState === false) {
|
||||
elem.visible = false;
|
||||
ONSControls.idleDisabled = true;
|
||||
} else {
|
||||
elem.visible = true;
|
||||
ONSControls.idleDisabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -282,11 +297,7 @@ ONSControls.setupInteractive = function () {
|
|||
|
||||
// Canvas
|
||||
this._idleInterval = setInterval(ONSControls.playIdleAnimation, 300000);
|
||||
this._controlsCanvas.stage.on("pointerdown", () => {
|
||||
this.stopIdleAnimation();
|
||||
clearInterval(ONSControls._idleInterval);
|
||||
ONSControls._idleInterval = setInterval(ONSControls.playIdleAnimation, 300000);
|
||||
});
|
||||
this._controlsCanvas.stage.on("pointerdown", ONSControls.resetIdleAnimation);
|
||||
|
||||
// A/B/X/Y
|
||||
const buttons = this._buttonsContainer.children;
|
||||
|
@ -329,6 +340,9 @@ ONSControls.setupInteractive = function () {
|
|||
// Show button
|
||||
this._showButton.on("pointerdown", this.toggle);
|
||||
}
|
||||
//=============================================================================
|
||||
// * Get all buttons
|
||||
//=============================================================================
|
||||
ONSControls.getControlElements = function() {
|
||||
return [
|
||||
this._dPadContainer, this._LBsprite,
|
||||
|
@ -406,6 +420,7 @@ ONSControls.replaceBackEvent = function() {
|
|||
ONSControls.openEditMode = function() {
|
||||
if (Graphics._canvas.hidden === false) {
|
||||
Graphics._canvas.hidden = true;
|
||||
this.idleDisabled = true;
|
||||
this.clearInteractive();
|
||||
this._buttonsContainer.interactive = true;
|
||||
for (elem of this.getControlElements()) {
|
||||
|
@ -422,6 +437,7 @@ ONSControls.openEditMode = function() {
|
|||
ONSControls.closeEditMode = function() {
|
||||
this._editModeText.visible = false;
|
||||
Graphics._canvas.hidden = false;
|
||||
this.idleDisabled = false;
|
||||
this.clearInteractive();
|
||||
this.setupInteractive();
|
||||
ConfigManager.ONSConfig.saveButtonsPosition();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue