屏幕之间的libgdx切换非常慢,有时会崩溃而没有任何日志

时间:2019-04-19 16:34:28

标签: libgdx

我正在使用libgdx来构建游戏,我使用了多个屏幕,并且它们之间的切换非常慢,有时会导致游戏崩溃,而无需在android设备上进行任何登录。我该如何解决这个问题?对于这个问题的原因,我完全一无所知。我在课堂上使用了几个动画和几个图像按钮,并使用了三个这样的类。

public class BabyGreen extends BabyScreen {


private BabyActor bg;
private BabyActor phone;
private AnimatedActor common;
private AnimatedActor plane,car,heli,boat,train,sub,truck,bus,police;
private ImageButton buttonLeft,buttonRight,buttonCenter;
private ImageButton 
button1,button2,button3,button4,button5,button6,button7,button8,button9;
private AnimatedActor actor;


public BabyGreen(Game g){
    super(g);
}

public void create () {


    bg = new BabyActor();
    bg.setTexture(new Texture("background-green.png"));
    bg.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());


    phone = new BabyActor();
    phone.setTexture(new Texture("green-phone.png"));
    phone.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());


    TextureRegion btLeft = new TextureRegion(new 
    Texture("ANIMALOFF.png"));
    Drawable drawableLeft = new TextureRegionDrawable(new 
    TextureRegion(btLeft));
    buttonLeft = new ImageButton(drawableLeft);

    TextureRegion btRight = new TextureRegion(new 
    Texture("NUMBEROFF.png"));
    Drawable drawableRight = new TextureRegionDrawable(new 
    TextureRegion(btRight));
    buttonRight = new ImageButton(drawableRight);

    TextureRegion btCenter = new TextureRegion(new 
    Texture("PHONEOFF.png"));
    Drawable drawableCenter = new TextureRegionDrawable(new 
    TextureRegion(btCenter));
    buttonCenter = new ImageButton(drawableCenter);

    TextureRegion bt1 = new TextureRegion(new Texture("PLANEOFF.png"));
    Drawable drawable = new TextureRegionDrawable(new 
    TextureRegion(bt1));
    button1 = new ImageButton(drawable);

    TextureRegion bt2 = new TextureRegion(new Texture("CAROFF.png"));
    Drawable drawable1 = new TextureRegionDrawable(new 
    TextureRegion(bt2));
    button2 = new ImageButton(drawable1);

    TextureRegion bt3 = new TextureRegion(new Texture("HELIOFF.png"));
    Drawable drawable2 = new TextureRegionDrawable(new 
    TextureRegion(bt3));
    button3 = new ImageButton(drawable2);

    TextureRegion bt4 = new TextureRegion(new Texture("BOATOFF.png"));
    Drawable drawable3 = new TextureRegionDrawable(new 
    TextureRegion(bt4));
    button4 = new ImageButton(drawable3);

    TextureRegion bt5 = new TextureRegion(new Texture("TRAINOFF.png"));
    Drawable drawable4 = new TextureRegionDrawable(new 
    TextureRegion(bt5));
    button5 = new ImageButton(drawable4);

    TextureRegion bt6 = new TextureRegion(new Texture("SUBOFF.png"));
    Drawable drawable5 = new TextureRegionDrawable(new 
    TextureRegion(bt6));
    button6 = new ImageButton(drawable5);

    TextureRegion bt7 = new TextureRegion(new Texture("TRUCKOFF.png"));
    Drawable drawable6 = new TextureRegionDrawable(new 
    TextureRegion(bt7));
    button7 = new ImageButton(drawable6);

    TextureRegion bt8 = new TextureRegion(new Texture("BUSOFF.png"));
    Drawable drawable7 = new TextureRegionDrawable(new 
    TextureRegion(bt8));
    button8 = new ImageButton(drawable7);

    TextureRegion bt9 = new TextureRegion(new Texture("POLICEOFF.png"));
    Drawable drawable8 = new TextureRegionDrawable(new 
    TextureRegion(bt9));
    button9 = new ImageButton(drawable8);



    car = new AnimatedActor();
    TextureRegion[] frames2 = new TextureRegion[4];
    for (int n = 1; n <= 4; n++)
    {
        String fileName = "car" + n + ".png";
        Texture tex = new Texture(fileName);
        tex.setFilter(Texture.TextureFilter.Linear, 
    Texture.TextureFilter.Linear);
        frames2[n-1] = new TextureRegion( tex );
    }
    Array<TextureRegion> framesArray2 = new Array<TextureRegion> 
   (frames2);

    final Animation anim2 = new Animation(0.1f, framesArray2, 
   Animation.PlayMode.LOOP);
    car.setAnimation(anim2);

   car.setSize(Gdx.graphics.getWidth()/2*0.5f,
   Gdx.graphics.getHeight()/2*0.5f);
    car.setPosition(phone.getWidth()/100*40,phone.getHeight()/100*55);
    car.setOrigin(car.getWidth()/2,car.getHeight()/2);

     stage.addActor(bg);
    stage.addActor(phone);


    Gdx.input.setInputProcessor(stage);

    buttonLeft.addListener(new InputListener(){
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int 
    pointer, int button) {

            game.setScreen(new BabyOrange(game));
            return false;
        }
    });
    buttonRight.addListener(new InputListener(){
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int 
    pointer, int button) {

            game.setScreen(new BabyBlue(game));
            return false;
        }
    });

    Table table = new Table();
    table.padLeft(40);
    table.setPosition(phone.getWidth()/2,phone.getHeight()/2*0.6f);
    table.row().size(stage1.getWidth()/100*20,stage1.getWidth()/100*20);
    table.add(buttonLeft);
    table.add(buttonCenter);
    table.add(buttonRight);
    table.row().size(stage1.getWidth()/100*18,stage1.getWidth()/100*18);
    table.add(button1);
    table.add(button2);
    table.add(button3);
    table.row().size(stage1.getWidth()/100*18,stage1.getWidth()/100*18);
    table.add(button4);
    table.add(button5);
    table.add(button6);
    table.row().size(stage1.getWidth()/100*18,stage1.getWidth()/100*18);
    table.add(button7);
    table.add(button8);
    table.add(button9);
    stage.addActor(table);


      }
    public void dispose(){
   stage.dispose();
   stage1.dispose();
   bg.getRegion().getTexture().dispose();
   phone.getRegion().getTexture().dispose();

   car.getRegion().getTexture().dispose();
   truck.getRegion().getTexture().dispose();

   }
   }

0 个答案:

没有答案