【发布时间】:2012-08-17 19:07:14
【问题描述】:
我是 AndEngine 的新手,我正在尝试按照 this tutorial 实现 hanoi 游戏。 将背景图片插入 gfx 文件夹并设置所有 onCreateResources 代码和 onCreateScene 代码后,我尝试运行该应用程序,我看到的只是一个代表我的背景图片的三角形,正如您在this image 中看到的那样。
这是我的代码:
final int CAMERA_WIDTH = 480;
final int CAMERA_HEIGHT = 800;
public EngineOptions onCreateEngineOptions() {
myCamera = new Camera(800, 480, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(false, ScreenOrientation.PORTRAIT_SENSOR,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
myCamera);
}
public ITextureRegion texture;
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
try {
// 1 - Set up bitmap textures
ITexture backgroundTexture = new BitmapTexture(
this.getTextureManager(), new IInputStreamOpener() {
public InputStream open() throws IOException {
return getAssets().open("gfx/background.png");
}
});
// 2 - Load bitmap textures into VRAM
backgroundTexture.load();
// 3 - Set up texture regions
this.mBackgroundTextureRegion = TextureRegionFactory
.extractFromTexture(backgroundTexture);
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// 1 - Create new scene
final Scene scene = new Scene();
Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
scene.attachChild(backgroundSprite);
}
由于我尝试自己解决此错误,我已经尝试过:
- 设置相机 FillResolutionPolicy(),对结果没有影响。
- 将背景创建为 BitmapTextureAtlas,BitmapTextureAtlasTextureRegionFactory.createFromAsset
- 调用 mEngine.getScene().setBackground 而不是 attachChild
- 使用其他 API 级别重新创建 Android 虚拟设备(已尝试 16、15)
另外,AndEngine 论坛中有一个帖子,this one 我没有找到答案。
【问题讨论】: