1

こんにちは、私は Android 開発の初心者です。

AndEngineを使って簡単なゲームを作りたいです。せっかくなのでサンプルを少し試してみました。しかし、apk ファイルを nexus7 にデプロイすると、. しかし、アプリを実行すると、画面の中央に白い背景で常に「Hello World」と表示されます。ただし、特定の背景色の画像を表示する必要があります。

これが私のコードです:

public class MainActivity extends SimpleBaseGameActivity {
private static final float CAMERA_WIDTH = 720;
private static final float CAMERA_HEIGHT = 480;
private Camera mCamera;
private BitmapTextureAtlas mBitmapTextureAtlas;
private Engine mEngine;
private TextureRegion mFaceTextureRegion;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public EngineOptions onCreateEngineOptions() {

    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true,
            ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
                    CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}

@Override
protected void onCreateResources() {

    this.mBitmapTextureAtlas = new BitmapTextureAtlas(
            mEngine.getTextureManager(), 32, 32,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(this.mBitmapTextureAtlas, this,
                    "face_box.png", 0, 0);

    getTextureManager().loadTexture(this.mBitmapTextureAtlas);
}

@Override
protected Scene onCreateScene() {

    this.mEngine.registerUpdateHandler(new FPSLogger());
    final Scene scene = new Scene();
    scene.setBackground(new Background(new Color(0, 255, 128)));
    final int centerX = (int) ((CAMERA_WIDTH - this.mFaceTextureRegion
            .getWidth()) / 2);
    final int centerY = (int) ((CAMERA_HEIGHT - this.mFaceTextureRegion
            .getHeight()) / 2);
    final Sprite face = new Sprite(centerX, centerY,
            this.mFaceTextureRegion, new VertexBufferObjectManager());
    scene.attachChild(face);

    return scene;
}

}

私は何を間違っていますか?前もって感謝します。

4

1 に答える 1

3

AndEngine SimpleBaseGameActivity を使用しているため、これは必要ありません。

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

コンテンツ ビューを設定しているため、「Hello world」が表示されます。onCreate へのオーバーライドを削除すると、機能するはずです。

于 2012-12-01T17:46:10.140 に答える