Почему мой спрайт не загружается, все, что я получаю, это привет мир в ландшафте - PullRequest
0 голосов
/ 18 февраля 2019

недавно я пытался настроить некоторые изображения для загрузки в центре экрана, чтобы проверить фоновые рисунки бегущей картинки для моего устройства, но по какой-то причине он не хочет загружаться?

код:

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загрузка файла в качестве фона для моей детализации я собираюсь сделать.Любая помощь будет благодарна.

...