AndEngine无法识别要加载的Sprite吗?

时间:2019-02-18 14:41:26

标签: sprite andengine

我开始与andEngine一起工作,正在尝试制作有关如何加载图像的快速参考指南,目前,我正在尝试从正在阅读的书中制作一个启动画面,事实证明这对某些人来说很难。原因。这是我的代码

import android.os.Bundle;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.engine.Engine;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.opengl.texture.Texture;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.util.Constants;

import java.io.IOException;

public class MainActivity extends BaseGameActivity {

// ===========================================================   // Constants   // ===========================================================

private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 320;

// ===========================================================   // Fields   // ===========================================================
private Camera mCamera;
private BitmapTextureAtlas myBitmapTextureAtlas;
private TextureRegion myTextureRegion;
private TextureRegion myBackgroundTextureRegion;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}



@Override
public Engine onCreateEngineOptions() {
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH,         CAMERA_HEIGHT);
    return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}



@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.myBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 512,  512,  TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    this.myTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.myBitmapTextureAtlas, this, "Splashscreen.png", 0, 0);
    this.myBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.myBitmapTextureAtlas, this, "Splashscreen.png", 0, 185);



}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException {
    final Scene scene = new Scene(1);
    /* Center the splash on the camera. */
    final float centerX =  ((CAMERA_WIDTH - this.myBackgroundTextureRegion.getWidth()) / 2);
    final float centerY = ((CAMERA_HEIGHT -  this.myBackgroundTextureRegion.getHeight()) / 2);

    /* Create the sprite and add it to the scene. */
                                                                      final Sprite splash = new Sprite(centerX, centerY, this.myBackgroundTextureRegion);
    scene.getLastChild().attachChild(splash);
    return scene;

  }

 @Override
  public void onPopulateScene(Scene pScene, OnPopulateSceneCallback    pOnPopulateSceneCallback) throws IOException {

}

}

我在创建精灵的地方是centerX,centerY和无法解析负载的地方,有人可以帮我吗?谢谢

0 个答案:

没有答案