1

私は AndEngine を学んでおり、いくつかの基本的なチュートリアルに従っています。画面にスプライトを読み込もうとしましたが、スプライトが壊れているように見えます。

これは私のコードです:

package com.example.andengine_demo;

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.sprite.Sprite;
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.ui.activity.BaseGameActivity;

public class MainActivity extends BaseGameActivity {

    // ===========================================================
    // Constants
    // ===========================================================
    static final int CAMERA_WIDTH = 720; 
    static final int CAMERA_HEIGHT = 480;

    private static final String TAG = "AndEngineTest";
    private BitmapTextureAtlas mBitmapTextureAtlas;
    private TextureRegion mPlayerTextureRegion;
    // ===========================================================
    // Fields
    // ===========================================================

    //private ZoomCamera mCamera;



@Override
public EngineOptions onCreateEngineOptions() {
    // TODO Auto-generated method stub
    Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}

@Override
public void onCreateResources(
        OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
    // TODO Auto-generated method stub
    mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box.png", 0, 0);
    mBitmapTextureAtlas.load();

}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
{
    this.mEngine.registerUpdateHandler(new FPSLogger());
    // TODO Auto-generated method stub
    Scene scene = new Scene();
    scene.setBackground(new Background(0f, 0f, 1f));

    final Sprite oPlayer = new Sprite(32,32, mPlayerTextureRegion, getVertexBufferObjectManager());
    scene.attachChild(oPlayer);
}

@Override
public void onPopulateScene(Scene pScene,
        OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
    // TODO Auto-generated method stub

}
}

そして、これはそれがどのように見えるかです:

壊れたスプライト

画像サイズが 32x32、画像のパスであることを確認し、読み込み時にさまざまなテクスチャ オプションを試しました。画像形式はPNGです。ご覧のとおり、背景色が設定した色と一致しません。私のエミュレータは GLES2.0 で動作するように (GPU エミュレーションで) 正しく構成されていると思います。問題は、カメラの高さとカメラの幅の値である可能性があると思いました。チュートリアルで見たので設定しましたが、正しいかどうかわかりません...私の解像度はWVGA800です。

何が悪いのかわからない... ゲームを作り続けるには、この問題を解決する必要があるので、どんな助けも歓迎します.

ありがとうございました!

4

1 に答える 1

4

SimpleBaseGameActivity代わりに拡張する必要があります。その後、それらのコールバックなどについて心配する必要はありません。

public class MainActivity extends SimpleBaseGameActivity {

// ===========================================================
// Constants
// ===========================================================
static final int CAMERA_WIDTH = 720; 
static final int CAMERA_HEIGHT = 480;

private static final String TAG = "AndEngineTest";
private BitmapTextureAtlas mBitmapTextureAtlas;
private TextureRegion mPlayerTextureRegion;
// ===========================================================
// Fields
// ===========================================================

//private ZoomCamera mCamera;



@Override
public EngineOptions onCreateEngineOptions() {
    // TODO Auto-generated method stub
    Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}

@Override
public void onCreateResources() {
    mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box.png", 0, 0);
    mBitmapTextureAtlas.load();
}

@Override
public Scene onCreateScene()
{
    this.mEngine.registerUpdateHandler(new FPSLogger());
    // TODO Auto-generated method stub
    Scene scene = new Scene();
    scene.setBackground(new Background(0f, 0f, 1f));

    final Sprite oPlayer = new Sprite(32,32, mPlayerTextureRegion, getVertexBufferObjectManager());
    scene.attachChild(oPlayer);
    return scene;
}

}
于 2012-08-15T16:08:33.380 に答える