我正在尝试了解andEngine中的精灵。我写了下面的代码来加载一个简单的图像“img”
package com.example.pxc;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;
public class TestActivity extends SimpleBaseGameActivity {
static final int CAMERA_WIDTH = 800;
static final int CAMERA_HEIGHT = 480;
BuildableBitmapTextureAtlas bbta;
ITextureRegion msr;
@Override
public EngineOptions onCreateEngineOptions() {
Camera 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() {
// TODO Auto-generated method stub
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
bbta = new BuildableBitmapTextureAtlas(mEngine.getTextureManager(), 256, 256);
msr=BitmapTextureAtlasTextureRegionFactory.createFromAsset(bbta, this, "img.png");
try{
bbta.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 1));
bbta.load();
} catch (TextureAtlasBuilderException e) {
e.printStackTrace();
}
}
@Override
protected Scene onCreateScene() {
Scene scene = new Scene();
Sprite mSprite = new Sprite(0, 0,
msr, mEngine.getVertexBufferObjectManager());
scene.attachChild(mSprite);
return scene;
}
}
上面的代码编译没有任何错误。当我运行代码时,我会看到模拟器上的黑屏而不是图像。为什么会这样?我该如何解决这个问题?