我做了一个相位器游戏,要放在网站上的一个框架中。如果玩家在游戏进行时点击网站上的其他任何地方,我有一个显示HTML元素以警告玩家的功能,在这里:
function showOnLoseFocus()
{
if( window.globalGame !== null && window.globalGame !== undefined )
{
document.getElementById('container_refocusWarning').style.display = 'block';
document.getElementById('refocusTitle').innerHTML = ((getHtmlTextFromXML('restore_default') === '' ? 'Game Paused' : getHtmlTextFromXML('restore_default')));
document.getElementById('refocusResume').innerHTML = ((getHtmlTextFromXML('restore_tap') === '' ? '(Tap to resume game)' : getHtmlTextFromXML('restore_tap')));
}
}
以上工作正常。
现在,我正在尝试制作一个类似的功能adLoseFocus
,旨在通知玩家广告正在完成,但在显示之前延迟 3 秒。相位器本身有一个内置的延迟功能,我在这里尝试过:
this.game.time.events.add(3000, adLoseFocus);
不幸的是,这似乎不起作用,所以我尝试修改adLoseFocus
以使用 setTimeOut,在这里:
function adLoseFocus( bIsMuted, p_callback, bIsAd = true)
{
adRegainMute = bIsMuted;
adActive = true;
window.globalGame.sound.mute = true;
if( window.globalGame !== null && window.globalGame !== undefined && bIsAd)
{
setTimeout(function() {
document.getElementById('container_refocusWarning').style.display = 'block';
document.getElementById('refocusTitle').innerHTML = getHtmlTextFromXML('restore_ad');
document.getElementById('refocusResume').innerHTML = getHtmlTextFromXML('restore_tap');
}, 3000);
}
fAdCallback = p_callback;
}
这也不起作用;警告会立即显示。我错过了什么吗?
我的错误,显然错误出在函数调用中。这样做:
adLoseFocus(true, callbackFunction)
由于某种原因,bIsAd
检查失败,即使它设置为 true 默认值也是如此。改为这样做:
adLoseFocus(true, callbackFunction, true)
确保它有效。