android - AndEngine 导入 GLES2 项目未运行

标签 android opengl-es-2.0 andengine

我正在尝试更新我的项目以使用 AndEngine GLES2 运行,但我遇到了一些问题。我找到了一篇文章,其中显示了要更改的内容,但它仍然无法正常工作。这正是我正在做的:

onCreateEngineOptions()

@Override
public EngineOptions onCreateEngineOptions() {
    Toast.makeText(this, "Touch the screen to add Logo.", Toast.LENGTH_LONG).show();
    CAMERA_WIDTH = getWindow().getWindowManager().getDefaultDisplay().getWidth();
    CAMERA_HEIGHT = getWindow().getWindowManager().getDefaultDisplay().getHeight();

    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);


    final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    engineOptions.getTouchOptions().setNeedsMultiTouch(false);
    return engineOptions;
}

onCreateResources()

public void onCreateResources() {

    this.mBitmapTextureAtlas = new BitmapTextureAtlas(4096, 4096, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    this.mFont = new Font(this.mBitmapTextureAtlas, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), 25, true, Color.BLACK);

    this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
    this.mEngine.getFontManager().loadFont(this.mFont);


    this.firstSprite =  BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "1.png", 0, 113); // 113x100
           // 36 other sprites, that's why I'm creating BitmapTextureAtlas with these size

    this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
}

onCreateScene()

@Override
public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    this.mScene = new Scene();
    this.mScene.setBackground(new Background(4, 4, 4));
    this.mScene.setOnSceneTouchListener(this);

    this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

    CAMERA_WIDTH = getWindow().getWindowManager().getDefaultDisplay().getWidth();
    CAMERA_HEIGHT = getWindow().getWindowManager().getDefaultDisplay().getHeight();

    final IAreaShape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);
    final IAreaShape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
    final IAreaShape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
    final IAreaShape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);

    final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.KinematicBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.KinematicBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.KinematicBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.KinematicBody, wallFixtureDef);

    this.mScene.attachChild(ground);
    this.mScene.attachChild(roof);
    this.mScene.attachChild(left);
    this.mScene.attachChild(right);

    this.mScene.registerUpdateHandler(this.mPhysicsWorld);
    this.mScene.setOnAreaTouchListener(this);

    final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 1);

    //Sprite 1
    Sprite face = new Sprite(CAMERA_WIDTH/2, 50, this.firstSprite);
    face.setUserData("petrol");
    Body body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    this.mScene.registerTouchArea(face);
    this.mScene.attachChild(face);
    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true));
            // 36 sprites....
return this.mScene;
    }

问题是,当我开始这个 Activity 时,它没有显示任何 Sprite ,即使我将它更改为白色,屏幕仍然是黑色的。

所以任何想法我的错误在哪里以及我做错了什么。 (在迁移到 AndEngine GLES2 之前,除 Android Honeycomb 外,其他一切正常,现在我正在运行 Android 2.3.4 的 HTC EVO 3d 上测试这个项目)。

提前致谢!

最佳答案

我不确定这是否是你的问题 - 我在添加之前遇到过类似的问题

    @Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception { //
    // TODO Auto-generated method stub

    pOnPopulateSceneCallback.onPopulateSceneFinished();
}

关于android - AndEngine 导入 GLES2 项目未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8882234/

相关文章:

opengl - 如何在桌面上创建 OpenGL ES 2 上下文?

xcode4 - OpenGL ES 2.0 指定顶点着色器的法线

ios - 不使用任何 Apple API 加载 GLSL 着色器

android - 创建声音时,AndEngine NullpointerException

java - 如何在 Android Studio 中构建 AndEngine?

android - Android 位置随机播放按钮

android - Gradle Sync 在 Android Studio 3.0 Canary 5 中失败

使用 MockContext 的 Android ApplicationTestCase

android - AndEngine - 支持多屏

android - 为什么setBackground和Drawable不能完全填满