И двигатель не распознает спрайт для загрузки? - PullRequest
0 голосов
/ 18 февраля 2019

Я начал работать с 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, и нагрузка не может быть решена, кто-нибудь, пожалуйста, помогите мне с этим?спасибо

...