AndEngine导入GLES2项目未运行

发布于 2024-12-27 04:41:22 字数 3967 浏览 1 评论 0原文

我正在尝试更新我的项目以使用 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;
    }

问题是,当我开始此活动时,它没有显示任何精灵,并且即使我将其更改为白色,屏幕仍保持黑色。

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

提前致谢!

I'm trying to update my project to run with AndEngine GLES2, but I have some problems. I find an article which shows what to change, but it's still not working. Here is exactly what I'm doing :

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;
    }

And the problem is that when I start this activity it's not showing non of the sprites and the screen remains black even if I change it to white color.

So any ideas where is my mistake and what I'm doing wrong. (Before moving to AndEngine GLES2 everything was working except on Android Honeycomb and now I'm testing this project on HTC EVO 3d which is running with Android 2.3.4).

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绾颜 2025-01-03 04:41:22

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

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

    pOnPopulateSceneCallback.onPopulateSceneFinished();
}

I'm not sure if this is your issue - I had similar problems before I added this

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

    pOnPopulateSceneCallback.onPopulateSceneFinished();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文