AndEngine sprite导致一个力量关闭

时间:2012-08-21 19:39:13

标签: andengine sprite forceclose

首次发布海报,Android编程新手。使用Eclipse classic,已经加载了android SDK和API。创建了一个hello world app,以及后面的文本发送应用程序(android dev site)。现在正在使用Jimmaru(http://jimmaru.wordpress.com/2011/09/28/andengine-simple-android-game-tutorial/)教程(GLES1)进行游戏,使用AndEngine(GLES1尽我所能告诉我,当我查找时没有“simpleBaseGameActivity”的超类。我已经让空白屏幕显示正常,但添加玩家精灵的步骤会导致应用程序执行/加载时关闭。< / p>

这是我的One Class(SimpleGame)

package com.example.game;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.view.Display;

public class SimpleGame extends BaseGameActivity {

// initiates view
private Camera mCamera;

// Main Scene
private Scene mMainScene;
private Sprite player;

// Textures
private BitmapTextureAtlas mBitmapTextureAtlas;
private TextureRegion mPlayerTextureRegion;

@Override
public Engine onLoadEngine() {
    final Display display = getWindowManager().getDefaultDisplay();
    int cameraWidth = display.getWidth();
    int cameraHeight = display.getHeight();

    mCamera = new Camera(0, 0, cameraWidth, cameraHeight);

    return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,
            new RatioResolutionPolicy(cameraWidth, cameraHeight), mCamera));
}

@Override
public void onLoadResources() {

    // This places player character on screen, file is in
    // assets/gfx/Player.png
    mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(this.mBitmapTextureAtlas, this, "Player.png",
                    0, 0);

    mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas);

}

@Override
public Scene onLoadScene() {
    mEngine.registerUpdateHandler(new FPSLogger());

    mMainScene = new Scene();
    mMainScene
            .setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    mMainScene.attachChild(player);

    final int PlayerX = this.mPlayerTextureRegion.getWidth() / 2;
    final int PlayerY = (int) ((mCamera.getHeight() - mPlayerTextureRegion
            .getHeight()) / 2);

    player = new Sprite(PlayerX, PlayerY, mPlayerTextureRegion);

    return mMainScene;
}

@Override
public void onLoadComplete() {
    // TODO Auto-generated method stub

}

}

这是我的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.game"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">
    <activity android:name="SimpleGame">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

</application>

这是我的LogCat文件

08-21 14:14:50.116: D/dalvikvm(12704): GC_EXTERNAL_ALLOC freed 76K, 50% free 2737K/5379K, external 0K/0K, paused 33ms

08-21 14:14:50.156: D/AndEngine(12704): UpdateThread interrupted. Don't worry - this Exception is most likely expected!

08-21 14:14:50.156: D/AndEngine(12704): java.lang.InterruptedException

08-21 14:14:50.156: D/AndEngine(12704):     at java.lang.Object.wait(Native Method)

08-21 14:14:50.156: D/AndEngine(12704):     at java.lang.Object.wait(Object.java:358)

08-21 14:14:50.156: D/AndEngine(12704):     at org.anddev.andengine.engine.Engine$State.waitUntilCanUpdate(Engine.java:722)

08-21 14:14:50.156: D/AndEngine(12704):     at org.anddev.andengine.engine.Engine.yieldDraw(Engine.java:472)

08-21 14:14:50.156: D/AndEngine(12704):     at org.anddev.andengine.engine.Engine.onTickUpdate(Engine.java:463)

08-21 14:14:50.156: D/AndEngine(12704):     at org.anddev.andengine.engine.Engine$UpdateThread.run(Engine.java:685)

08-21 14:14:50.316: D/AndroidRuntime(12704): Shutting down VM

08-21 14:14:50.316: W/dalvikvm(12704): threadid=1: thread exiting with uncaught exception (group=0x401cc568)

08-21 14:14:50.316: E/AndroidRuntime(12704): FATAL EXCEPTION: main

08-21 14:14:50.316: E/AndroidRuntime(12704): java.lang.NullPointerException

08-21 14:14:50.316: E/AndroidRuntime(12704):    at org.anddev.andengine.entity.Entity.attachChild(Entity.java:482)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at com.example.game.SimpleGame.onLoadScene(SimpleGame.java:71)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at org.anddev.andengine.ui.activity.BaseGameActivity.doResume(BaseGameActivity.java:169)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at org.anddev.andengine.ui.activity.BaseGameActivity.onWindowFocusChanged(BaseGameActivity.java:85)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2106)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at android.view.View.dispatchWindowFocusChanged(View.java:3925)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:665)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1982)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at android.os.Handler.dispatchMessage(Handler.java:99)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at android.os.Looper.loop(Looper.java:130)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at android.app.ActivityThread.main(ActivityThread.java:3703)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at java.lang.reflect.Method.invokeNative(Native Method)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at java.lang.reflect.Method.invoke(Method.java:507)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)

08-21 14:14:50.316: E/AndroidRuntime(12704):    at dalvik.system.NativeStart.main(Native Method)

08-21 14:14:54.190: I/Process(12704): Sending signal. PID: 12704 SIG: 9

非常感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

移动此行

mMainScene.attachChild(player);

到这两行之间的一点

player = new Sprite(PlayerX, PlayerY, mPlayerTextureRegion);

return mMainScene;