3

AndengineLive壁紙拡張機能を使用してライブ壁紙を作成しています。問題は、OnCreateSceneメソッドでスプライト(背景画像)をアタッチしようとすると、nullポインター例外が発生することです。誰かがこれを手伝ってくれますか?

以下は私のコードです:-

@Override
public EngineOptions onCreateEngineOptions() {

    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    EngineOptions engineOptions = new EngineOptions(false, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
    return engineOptions;

}

@Override
public void onCreateResources(
        OnCreateResourcesCallback rsrCallback)
        throws Exception {

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 
    background = new BitmapTextureAtlas(this.getTextureManager(), 480, 320);
    backTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(background,this.getAssets(), "background_small.png", 0, 0);
    background.load();

    rsrCallback.onCreateResourcesFinished();
}

@Override
public void onCreateScene(OnCreateSceneCallback sceneCallback)
        throws Exception {
    // creating main scene
    mMainScene = new Scene();
    IBackground myBack = new  Background(0.0f, 0.0f, 0.0f);
    mMainScene.setBackground(myBack);

    final Sprite bkground = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, backTR, getVertexBufferObjectManager());
    mMainScene.getLastChild().attachChild(bkground);

    sceneCallback.onCreateSceneFinished(mMainScene);  
}

行mMainScene.getLastChild()。attachChild(bkground)で、nullポインターを取得します。スタックトレースが添付されます。

エラーのスタックトレース

4

1 に答える 1

2

壁紙にスプライトの背景を追加する別の解決策を見つけました。

SpriteBackground クラスを使用します:-

mMainScene.setBackground(new SpriteBackground(new Sprite(0, 0, backTR, this.getVertexBufferObjectManager())));

これにより、以前に取得していた null ポインターが解決されます。

于 2012-09-20T06:48:27.847 に答える