0

我正在使用 libgdx 开发游戏。资源由 AssetManager 管理。

Libgdx中所示,需要重新加载像纹理这样的托管 OpenGL 资源。

因此,在我的 ApplicationListener#resume() 方法中,我切换到加载屏幕并再次调用 AssetManager#update()。

现在我正在实施一些广告。

我遇到的问题是,如果我展示插页式广告。当这个广告关闭并且我返回游戏时,加载屏幕再次出现并且需要一些时间,这很烦人。

(我已按照本指南将广告集成到我的 Libgdx Android 代码中:Libgdx ads

有任何想法吗?谢谢!!

这是我的代码:

public class MyGame extends Game implements InputProcessor {    

public Assets assets;
public SpriteBatch sb;
public Screen ScrSplash;
public Screen ScrLoading;
public Screen ScrMainMenu;  

public IActivityRequestHandler myRequestHandler;        

public GamPrincipal(IActivityRequestHandler handler) {  
    myRequestHandler = handler;
}   

@Override
public void create() {      
    sb = new SpriteBatch();
    ScrSplash       = new ScrSplash(this, sb);
    ScrLoading      = new ScrLoading(this, sb);
    ScrMainMenu     = new ScrMainMenu (this, sb);
    assets = new Assets();      
    setScreen(ScrSplash);
}

//====

public class ScrMyScreen implements Screen, InputProcessor{

private MyGame game;    
private OrthographicCamera camara;
private SpriteBatch sb;             
private Sprite sprBackground;
//…more…//

public ScrMyScreen(MyGame game, SpriteBatch sb) {       
    this.game = game;
    this.sb = sb;
}   

@Override
public void render(float delta) {       
      sb.begin();    
        sprBackground.draw(sb);
            /// 
                //…more…//
    sb.end();
}   


@Override
public void resize(int width, int height) { 
}

@Override
public void show() {            
    sprFondo             = game.assets.sprBackground;
    sprLblTitle          = game.assets.sprTitle;
        //…more…//


    //**************Show Ads*******************
    game.myRequestHandler.showAds(true);
}

@Override
public void hide() {
    dispose();
}

@Override
public void pause() {       
}

@Override
public void resume() {
    //Show loading screen   
    game.setScreen(game.ScrLoading);        
}

@Override
public void dispose() {
    //Call Dispose assets method
}

//===

public class ScrLoading implements Screen {

private MyGame game;
private Sprite sprBG;
private OrthographicCamera camera;
private SpriteBatch sb;
//… 

public ScrLoading(GamPrincipal juego, SpriteBatch sb) {     
    this.game = game;
    this.sb = sb;   
}   

@Override
public void render(float delta) { 

    if(Recursos.manager.update()) { 
            game.setScreen(game. ScrMyScreen); 
    }       

   sb.begin();     
        sprBG.draw(sb);
    //…more… (draw text : “loading…”  )  
        //  
   sb.end();

}

@Override
public void resize(int width, int height) {
}

@Override
public void show() {        
    texture = new Texture("data/images/bg.png");    
    sprBG = new Sprite (texture);
    Assets.manager.update();
}

@Override
public void hide() {
    dispose();
}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void dispose() {
    //Call Dispose assets method
}
4

1 回答 1

0

如果您使用 AssetManager,则不必重新加载您的资产。它会自动缓存它们。所以只需删除简历中的那一行。

于 2013-06-16T04:11:20.407 回答