我的子画面为什么不加载,我得到的只是景观中的世界

时间:2019-02-18 20:23:35

标签: android load 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.entity.util.FPSLogger;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.opengl.texture.region.TextureRegion;
 import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;

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 EngineOptions onCreateEngineOptions() {
    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera); }



@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, 0);
myBitmapTextureAtlas.load();


}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException {
    this.mEngine.registerUpdateHandler(new FPSLogger());
    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, getVertexBufferObjectManager() );
    scene.getLastChild().attachChild(splash);

}

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

}

}

上面的代码运行了,但是出现的只是Hello World图标,该图标显示了activity_main的示例,但是我正在寻找一种方法,以便将png文件加载为我要做的细节的背景。任何帮助都会感谢。

0 个答案:

没有答案