1

初めてのポスター、Androidプログラミングの初心者。Eclipseクラシックを使用して、AndroidSDKとAPIをロードします。hello worldアプリと、それに続くテキスト送信アプリ(android dev site)を作成しました。現在、Jimmaru(http://jimmaru.wordpress.com/2011/09/28/andengine-simple-android-game-tutorial/)チュートリアル(GLES1)を使用して、AndEngine(GLES1を可能な限り使用)を使用してゲームに取り組んでいます。教えてください、私が探したときに「simpleBaseGameActivity」のスーパークラスがありませんでした。空白の画面が正常に表示されましたが、プレーヤースプライトを追加する手順により、アプリの実行/読み込みが強制的に終了します。

これが私のワンクラス(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

どんな助けでも大歓迎です、ありがとう。

4

1 に答える 1

0

この行を移動します

mMainScene.attachChild(player);

これらの2つの線の間のポイントに

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

return mMainScene;
于 2012-08-21T19:44:30.807 に答える