无法在屏幕

时间:2016-08-04 08:16:05

标签: android image textures andengine

我正在使用AndEngine GLES2,我试图在手机上加载图像,但我得到的是黑屏

以下是我的代码:

public class BaseActivity extends SimpleBaseGameActivity {

static final int CAMERA_WIDTH = 800;
static final int CAMERA_HEIGHT = 480;

public Font mFont;
public Camera mCamera;

private MainMenuScene mainMenuScene;
public Engine mEngine;
public Scene mScene;
public BuildableBitmapTextureAtlas mBitmapTextureAtlas;
public ITextureRegion mITextureRegion;



@Override
public EngineOptions onCreateEngineOptions() {

    instance = this;
    mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}

@Override
protected void onCreateResources() {

    mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);
    mFont.load();

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    mITextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, this, "splash1.png");
    try {
        mBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 1));
    } catch (TextureAtlasBuilderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mBitmapTextureAtlas.load();
}

@Override
protected Scene onCreateScene() {

    final float positionX = CAMERA_WIDTH * 0.5f;
    final float positionY = CAMERA_HEIGHT * 0.5f;
    Sprite mSprite = new Sprite(positionX, positionY, mITextureRegion, mEngine.getVertexBufferObjectManager());
    mScene.attachChild(mSprite);
    return mCurrentScene;
}

Logcat显示我的onCreateResources和onCreateScene中有一个nullPointerException,我不知道出了什么问题。可能是什么问题?

1 个答案:

答案 0 :(得分:0)

一个错误是因为您从未创建过Scene对象,然后尝试将精灵附加到它,另一个错误是VertexbufferObjectManager不是Engine类的,而是SimpleBaseGameActivity类。 onCreateScene()变为:

  import os

  def rename_file():

  #function definition

   file_name = os.listdir(r"C:\pyscripts\prank")
   path = os.getcwd()
   print(path)

   rename_file()  # function calling

我还注释了一些变量以使其构建,但我怀疑这些是由于删除了代码示例:

    @Override
    protected Scene onCreateScene() {

        mScene = new Scene();
        final float positionX = CAMERA_WIDTH * 0.5f;
        final float positionY = CAMERA_HEIGHT * 0.5f;
        Sprite mSprite = new Sprite(positionX, positionY, mITextureRegion, getVertexBufferObjectManager());
        mScene.attachChild(mSprite);
        return mScene;
    }