我最近开始使用Andengine。我在教程视频的帮助下编写了这段代码。我想设置背景颜色并在场景中添加一个球(top.png)。 当我运行程序黑屏时,模拟器抛出错误后不久 我遇到了以下错误:
UpdateThread interrupted. Don't worry - this EngineDestroyedException is most likely expected!
org.andengine.engine.Engine$EngineDestroyedException
at org.andengine.engine.Engine.throwOnDestroyed(Engine.java:574)
at org.andengine.engine.Engine.onTickUpdate(Engine.java:560)
at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)
and my code:
package com.example.oyundeneme2;
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.scene.background.Background;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.region.TiledTextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
import android.view.Display;
public class OyunEkrani1 extends BaseGameActivity{
private static final int CAMERA_WIDTH=800;
private static final int CAMERA_HEIGHT=480;
private Camera myCamera;
private BitmapTextureAtlas myBackgroundTextureAtlas;
private TextureRegion myBackgroundTextureRegion;
//private Engine myEngine;
private Scene myScene;
private TiledTextureRegion myCircleFaceTextureRegion;
@Override
public EngineOptions onCreateEngineOptions() {
this.myCamera=new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
final Display myDisplay=getWindowManager().getDefaultDisplay();
EngineOptions FixedStepEngine=new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), myCamera);
return FixedStepEngine;
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.myBackgroundTextureAtlas=
new BitmapTextureAtlas(null,1024,512,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.myCircleFaceTextureRegion =BitmapTextureAtlasTextureRegionFactory.createTiledFrom
Asset(this.myBackgroundTextureAtlas, this, "top.png", 60, 60, 0, 0); // 64x32
this.mEngine.getTextureManager().loadTexture(this.myBackgroundTextureAtlas);
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
mEngine.registerUpdateHandler(new FPSLogger());
myScene = new Scene();
myScene.setBackground(new Background(0.59804f, 0.5274f, 0.5784f));
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:-1)
在“onCreateScene”中返回你的场景。试试这个