在AndEngine中加载SVG

时间:2011-12-30 15:08:59

标签: java android andengine

是否有人熟悉AndEngine并加载svg?

现在我正在尝试为场景加载背景,但由于某种原因它根本不显示..

这是我用来加载SVG并将其附加到场景的代码。

//In my onLoadResources method
     this.mBuildableTexture = new BuildableBitmapTexture(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
         SVGTextureRegionFactory.setAssetBasePath("gfx/");
          this.mSVGTestTextureRegions = SVGTextureRegionFactory.createFromAsset(this.mBuildableTexture, this, "background.svg", 16, 16);

//OnLoadScene method

final BaseTextureRegion baseTextureRegion = this.mSVGTestTextureRegions;
             if(baseTextureRegion instanceof TextureRegion) {
             final TextureRegion Region = (TextureRegion)baseTextureRegion;

             final float centerX = this.mCamera.getWidth() / 2;
             final float centerY = this.mCamera.getHeight() / 2;

             final float x = centerX - SIZE * 0.5f;
             final float y = centerY - SIZE * 0.5f;

             Sprite backgroundSprite = new Sprite(x,y,SIZE,SIZE,Region);
                     /*protected void onInitDraw(final GL10 pGL)
                        {
                           super.onInitDraw(pGL);
                           GLHelper.enableTextures(pGL);
                           GLHelper.enableTexCoordArray(pGL);
                           GLHelper.enableDither(pGL);
                        }
             };*/

            mScene.setBackground(new SpriteBackground(0.0f,0.0f,0.0f,backgroundSprite));
             backgroundSprite.setIgnoreUpdate(true);
             }

2 个答案:

答案 0 :(得分:6)

您是否在loadResources的代码中包含以下语句:

    try {
        this.mBuildableTexture.build(new BlackPawnTextureBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(1));
    } catch (final TextureAtlasSourcePackingException e) {
        Debug.e(e);
    }

    this.mEngine.getTextureManager().loadTexture(this.mBuildableTexture);

答案 1 :(得分:5)

Imo BlackPawnTextureAtlasBuilder类的命名非常直观,如:

  1. 这是一个实现ITextureAtlasBuilder接口
  2. javadoc类说:

  3. : - )