Я хочу создать простую игру, и я хочу использовать andengine.
Поэтому я решил протестировать библиотеку с помощью этого кода:
public class PrisonBreakActivity extends BaseGameActivity {
private ZoomCamera mCamera;
private BitmapTextureAtlas mTexture;
private TextureRegion mFaceTextureRegion;
private Scene mScene;
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
/** Called when the activity is first created. */
@Override
public Engine onLoadEngine() {
// TODO Auto-generated method stub
return null;
}
@Override
public void onLoadResources() {
this.mTexture = new BitmapTextureAtlas(64, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/man.png", 0, 0);
this.mEngine.getTextureManager().loadTexture(this.mTexture);
}
@Override
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
this.mScene = new Scene();
this.mScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
this.mScene.setOnSceneTouchListener(new IOnSceneTouchListener() {
@Override
public boolean onSceneTouchEvent(Scene pScene,
TouchEvent pSceneTouchEvent) {
// TODO Auto-generated method stub
if(pSceneTouchEvent.isActionDown()) {
PrisonBreakActivity.this.loadNewTexture();
}
return true;
}
});
return this.mScene;
}
@Override
public void onLoadComplete() {
// TODO Auto-generated method stub
}
private void loadNewTexture() {
MathUtils mu = new MathUtils();
//final TextureRegion faceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/man.png", 0, 0);
final float x = (CAMERA_WIDTH - mFaceTextureRegion.getWidth()) * mu.RANDOM.nextFloat();
final float y = (CAMERA_HEIGHT - mFaceTextureRegion.getHeight()) * mu.RANDOM.nextFloat();
final Sprite clickToUnload = new Sprite(x, y, mFaceTextureRegion);
this.mScene.attachChild(clickToUnload);
}
}
Я всегда получаю исключение NullPointerException в библиотеке (BaseGameActivity).Файл man.png находится в /asset/gfx/.
GameBaseActivity (from Andengine, Error in applyEngineOptions):
@Override
protected void onCreate(final Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState);
this.mPaused = true;
this.mEngine = this.onLoadEngine();
this.applyEngineOptions(this.mEngine.getEngineOptions());
this.onSetContentView();
}
Ошибка:
04-03 16: 22: 27.238: E / AndroidRuntime (425): вandroid.app.ActivityThread.performLaunchActivity (ActivityThread.java:2663)
04-03 16: 22: 27.238: E / AndroidRuntime (425): в android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2679)
04-03 16: 22: 27.238: E / AndroidRuntime (425): на android.app.ActivityThread.access $ 2300 (ActivityThread.java:125) 04-03 16: 22: 27.238: E /AndroidRuntime (425): на android.app.ActivityThread $ H.handleMessage (ActivityThread.java:2033)
04-03 16: 22: 27.238: E / AndroidRuntime (425): на android.os.Handler.dispatchMessage (Handler.java:99) 04-03 16: 22: 27.238: E / AndroidRuntime (425): на android.os.Looper.loop (Looper.java:123) 04-03 16: 22: 27.238: E/ AndroidRuntime (425): в android.app.ActivityThread.main (ActivityThread.java:4627) 04-03 16: 22: 27.238: E / AndroidRuntime (425): в java.lang.reflect.Method.invokeNative (собственный метод) 04-03 16: 22: 27.238: E / AndroidВремя выполнения (425): в java.lang.reflect.Method.invoke (Method.java:521) 04-03 16: 22: 27.238: E / AndroidRuntime (425): в com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:868) 04-03 16: 22: 27.238: E / AndroidRuntime (425): на com.android.internal.os.ZygoteInit.main (ZygoteInit.java:626) 04-03 16:22: 27.238: E / AndroidRuntime (425): at dalvik.system.NativeStart.main (собственный метод) 04-03 16: 22: 27.238: E / AndroidRuntime (425): вызвано: java.lang.NullPointerException 04-03 16: 22: 27.238: E / AndroidRuntime (425): в org.anddev.andengine.ui.activity.BaseGameActivity.onCreate (BaseGameActivity.java:65) 04-03 16: 22: 27.238: E / AndroidRuntime (425): вandroid.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1047) 04-03 16: 22: 27.238: E / AndroidRuntime (425): в android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2627)
Пожалуйста, помогите.