0

我用 Andengine 开发了一个游戏!它有 100 张照片(大约 15mb)。当我运行这个应用程序时,它会黑屏大约 10 秒。我想在加载其他 100 张图像时加载图像。

public void onLoadResources() {

      for(i=0;i<100;i++)
      {
          textCircle[i]=new Texture(1024,512,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
          textRegCircle[i] = TextureRegionFactory.createFromAsset(textCircle[i], this, "circlesBlue/"+i+".jpg", 0, 0);
          mEngine.getTextureManager().loadTexture(textCircle[i]);

      }
4

1 回答 1

0

我添加了我的类来加载集合图像。

public class Game extends BaseGameActivity {

private Scene dScene;
private TextureRegion dLoadingRegion;

Handler dHandler = new Handler() {
    public void handleMessage(android.os.Message msg) {
        switch (msg.what) {
        case 0:
            setYourSceneData();
            break;
        }
    };
};

@Override
public Engine onLoadEngine() {
    return null;
}

public void onLoadResources() {
    BitmapTextureAtlas BitmapTextureAtlas = new BitmapTextureAtlas(512,
            512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    dLoadingRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(BitmapTextureAtlas, this,
                    "your loading image path", 0, 0);
    getTextureManager().loadTextures(BitmapTextureAtlas);
}

private void loadOtherGameGraphics() {
    // here load your other region
           for(i=0;i<100;i++)
          {
               textCircle[i]=new Texture(1024,512,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
               textRegCircle[i] = TextureRegionFactory.createFromAsset(textCircle[i], this, "circlesBlue/"+i+".jpg", 0, 0);
               mEngine.getTextureManager().loadTexture(textCircle[i]);

          }
}

@Override
public Scene onLoadScene() {
    dScene = new Scene();
    dScene.attachChild(new Sprite(0, 0, Helper.CAMERA_WIDTH,
            Helper.CAMERA_HEIGHT, dLoadingRegion));
    new Thread(new Runnable() {
        @Override
        public void run() {
            loadOtherGameGraphics();
            dHandler.sendEmptyMessage(0);
        }
    }).start();
    return dScene;
}

public void setYourSceneData() {
    // here set your game data
    // and remove your loading image
}

@Override
public void onLoadComplete() {

}

}

于 2013-03-21T13:36:36.310 回答