0
我想了解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;
}
}
上面的代碼編譯沒有任何錯誤。當我運行代碼時,我看到模擬器上的黑色屏幕而不是圖像。爲什麼會發生?我該如何解決這個問題?
這可能是因爲你的仿真器是不支持提供設置gles2.Look at my post it may help you – Rama
img.png有多大?我懷疑你的TextureAtlas可能不夠大以容納圖像。我認爲如果問題是模擬器設置,它只會出錯,不會顯示黑屏。 – jmroyalty