加载AutoParallaxBackground Andengine纹理

时间:2015-05-15 09:51:02

标签: android andengine

我是 andengine 的新秀。目前我正在开发一个简单的andengine游戏项目,我想在其中加载视差背景。我按照 Nicolas Gramlich 在他的视差背景示例中显示的步骤。但是在运行代码之后我遇到了这个问题,看到一个带有一些闪烁颜色的黑色屏幕

我认为这是我的 buildableTextureAtlas ParallaxTexture 的问题所以这是我的代码来自 ResourceManager

public ITiledTextureRegion playerTiledTextureRegion;
public ITiledTextureRegion enemyTiledTextureRegion;
public ITextureRegion platformTextureRegion;
public ITextureRegion cloudOneTextureRegion;
public ITextureRegion cloudTwoTextureRegion;
public ITextureRegion cloudThreeTextureRegion;



private BuildableBitmapTextureAtlas gameTextureAtlas;


public BitmapTextureAtlas mAutoParallaxBackgroundTexture;

public ITextureRegion mParallaxLayerBack;
public ITextureRegion mParallaxLayerMid;
public ITextureRegion mParallaxLayerFront;

//sounds
Sound soundFall;
Sound soundJump;

//music
Music music;

//font
Font scoreFont;

这是我的 LoadResource ()方法

public void loadResources(){
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    gameTextureAtlas = new BuildableBitmapTextureAtlas(mGameActivity.getTextureManager(), 1024,
            512,BitmapTextureFormat.RGBA_8888,TextureOptions.NEAREST_PREMULTIPLYALPHA);

    playerTiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(gameTextureAtlas,mGameActivity.getAssets(), 
            "player.png", 3, 1);
    enemyTiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(gameTextureAtlas, mGameActivity.getAssets(),
            "enemy.png", 1, 2);
    cloudOneTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTextureAtlas, mGameActivity.getAssets(), "cloud1.png");
    cloudTwoTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTextureAtlas, mGameActivity.getAssets(), "cloud2.png");

    platformTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTextureAtlas, mGameActivity.getAssets(), "platform.png");

    mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(mGameActivity.getTextureManager(), 1024, 512);
    mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mAutoParallaxBackgroundTexture, mGameActivity, "parallax_background_layer_front.png", 0, 0);
    mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mAutoParallaxBackgroundTexture, mGameActivity, "parallax_background_layer_back.png", 0, 188);
    mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mAutoParallaxBackgroundTexture, mGameActivity, "parallax_background_layer_mid.png", 0, 669);


    try{
        gameTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(2, 0, 2));

        /*gameTextureAtlas.load();*/
        mAutoParallaxBackgroundTexture.load();

    }catch(final TextureAtlasBuilderException e){
        e.printStackTrace();
        throw new RuntimeException("error while loading textures", e);
    }
}

现在来自 GameScene

Scene scene = new Scene();
    AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, 200, resManager.mParallaxLayerBack, resManager.vbom)));
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, resManager.mParallaxLayerMid, resManager.vbom)));
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, 400, resManager.mParallaxLayerFront, resManager.vbom)));
    /*Sprite cloud1 = new Sprite(200,300, resManager.cloudOneTextureRegion, resManager.vbom);
    Sprite cloud2 = new Sprite(300,600, resManager.cloudTwoTextureRegion, resManager.vbom);*/

    scene.setBackground(autoParallaxBackground);

尝试创建autoParallaxBackground并将其设置为当前的Scene对象,但在运行代码后我得到了一个黑色和模糊的闪烁屏幕。请帮帮我。我解决了这个问题后整整一夜。

0 个答案:

没有答案