如何在libGdx中设置跨多个用途的跨媒体广告之间的时间间隔
我正在制作一个简单的Ketchapp风格的游戏,我想在玩家死后出现一个插播广告如何在libGdx中设置跨多个用途的跨媒体广告之间的时间间隔,libgdx,ads,Libgdx,Ads,我正在制作一个简单的Ketchapp风格的游戏,我想在玩家死后出现一个插播广告 public class GameOverAd { private static final int RESET = -1; private static long startTime = RESET; private static long currentTime; private static int secondsPassedSinceLastAd; public G
public class GameOverAd {
private static final int RESET = -1;
private static long startTime = RESET;
private static long currentTime;
private static int secondsPassedSinceLastAd;
public GameOverAd(){
if (startTime == RESET){
startTime = System.currentTimeMillis();
//first time showOrLoadInterstitial() runs it will load the ad
//second time showOrLoadInterstitial() runs it will show the ad
GameMain.handler.showOrLoadInterstitial();//loads
}
}
public void adCheck(){
currentTime = System.currentTimeMillis();
secondsPassedSinceLastAd = (int)((currentTime - startTime) /1000);
if(secondsPassedSinceLastAd >= 20){//seconds between ads
showAd();
}
else{
}
}
public void showAd(){
GameMain.handler.showOrLoadInterstitial();//shows add
startTime = RESET;
}
}
这是我当前使用的类,构造函数在游戏开始时使用,adCheck方法在玩家死亡时运行
public class GameOverAd {
private static final int RESET = -1;
private static long startTime = RESET;
private static long currentTime;
private static int secondsPassedSinceLastAd;
public GameOverAd(){
if (startTime == RESET){
startTime = System.currentTimeMillis();
//first time showOrLoadInterstitial() runs it will load the ad
//second time showOrLoadInterstitial() runs it will show the ad
GameMain.handler.showOrLoadInterstitial();//loads
}
}
public void adCheck(){
currentTime = System.currentTimeMillis();
secondsPassedSinceLastAd = (int)((currentTime - startTime) /1000);
if(secondsPassedSinceLastAd >= 20){//seconds between ads
showAd();
}
else{
}
}
public void showAd(){
GameMain.handler.showOrLoadInterstitial();//shows add
startTime = RESET;
}
}
只要玩家不关闭应用程序,此代码就可以正常工作,当玩家死亡时,使用250秒后会显示一个add,但问题是,如果播放器在249秒后退出,计时器将重置,用户将永远看不到广告。我如何使计时器从停止计时的同一位置继续计数?你必须在关闭时保存剩余时间,并在应用程序启动时重新读取。我建议为此使用Preferences类