如何在AndEngine中显示位图精灵?

我是AndEngine游戏开发的新手。我正在尝试加载并显示单个精灵,但是屏幕上出现了没有精灵的空白blcak屏幕。这是代码:

public class MainActivity extends SimpleBaseGameActivity {

static final int CAMERA_WIDTH = 800; 
static final int CAMERA_HEIGHT = 480;

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

@Override
public EngineOptions onCreateEngineOptions() {

    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
protected void onCreateResources() {
    mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "gfx/face_box.png", 0, 0);
    mBitmapTextureAtlas.load();
}

@Override
protected Scene onCreateScene() {

    this.mEngine.unregisterUpdateHandler(new FPSLogger());

    Scene scene = new Scene();
    scene.setBackground(new Background(3f, 6f, 2f));
    Sprite Player = new Sprite(32, 32, mPlayerTextureRegion, getVertexBufferObjectManager());
    Camera mCamera = new Camera(0, 0, CAMERA_WIDTH , CAMERA_HEIGHT);
    Player.setPosition(mCamera.getWidth()/2 - Player.getWidth()/2,
            mCamera.getHeight() - Player.getHeight() - 10);
    scene.attachChild(Player);



    return scene;
}

谁能告诉我这里是什么错误???任何有用的帮助将不胜感激。

Uwais A

您的代码有一些问题:

  1. 更改unregisterUpdateHandlerregisterUpdateHandler
  2. CameraSprite可能(应该)应该是使用它们的方法引用的全局变量。
  3. 更改Playerplayer(这只是一个约定,但很有用)。
  4. 初始化player前两个参数时,位置不是大小-这将节省您必须对进行额外的方法调用的时间setPosition()
  5. BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");在的开头onCreateResources()然后更改"gfx/face_box.png""face_box.png"

1,2和4几乎是必不可少的,3和5是可选的,但我建议您使用它们来简化。

这样可以解决问题吗?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章