【问题标题】:Add background to Andengine scene Android为Andengine场景Android添加背景
【发布时间】:2012-06-07 14:22:34
【问题描述】:

我想设置我的场景背景,但我不知道如何设置!我已经阅读了很多关于此的内容,但我无法使其正常工作。是我从 Andengine 开始的,并且很难找到我的问题的准确信息,一切都是主观的。

好吧,我已经在一个场景中实现了启动画面,同时加载了所有资源和场景。 (https://sites.google.com/site/matimdevelopment/splash-screen---easy-way)

然后,我必须为我的 menuScene 设置一个背景,我认为我需要一个 TextureRegion 和一个 BitmapTextureAtlas 来创建每个背景。我这样做:

声明的纹理:

    //Fondo escenas
private TextureRegion menuBgTexture;
private BitmapTextureAtlas menuBackgroundTexture;

加载资源和加载场景(在 Splash 结束时由 onPopulateScene 调用)

public void loadResources() 
{
    //FondoMenu
    menuBackgroundTexture = new BitmapTextureAtlas(null, 480, 320, TextureOptions.DEFAULT);
    menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.menuBackgroundTexture, this, "menubg.png", 0, 0);
    //Cargamos los fondos
    mEngine.getTextureManager().loadTexture(this.menuBackgroundTexture);

}

private void loadScenes()
{
    //Menú
    menuScene = new Scene();
    final float centerX = (CAMERA_WIDTH - menuBgTexture.getWidth()) / 2;
    final float centerY = (CAMERA_HEIGHT - menuBgTexture.getHeight()) / 2;
    SpriteBackground bg = new SpriteBackground(new Sprite(centerX, centerY, menuBgTexture));
    menuScene.setBackground(bg);
    //menuScene.setBackground(new Background(50, 0, 0));
    //Options
    optionsScene = new Scene();
    //Juego
    gameScene = new Scene();
    //Pausa
    pauseScene = new Scene();
    //Gameover
    gameOverScene = new Scene();
}

加载资源不显示错误,但 loadScenes,行: SpriteBackground bg = new SpriteBackground(new Sprite(centerX, centerY, menuBgTexture));

说我要设置一个新属性(ISpriteVertexBufferObject),嗯,这是什么?

【问题讨论】:

  • 您使用的是哪个 GLES? GLES2?我在 GLES2 中有 onCreateResources()。我不知道为什么 Nicolas Gramlich 决定像这样重命名关键函数,以及为什么他创建了一个没有文档的引擎/库。有人可以提供帮助吗?
  • 谁知道他在文档方面的想法,上帝禁止你在 andengine 论坛上谈论这个,如果你被告知你应该阅读源代码并工作它出来了,我的意思是这一切都很好,但在源代码中甚至没有任何 cmets。真可惜,它是一个不错的小型开源引擎,只是我的两分钱:D
  • 我也面临着类似的问题...我无法设置我的背景...这里是代码 ..menuBackgroundTexture = new BitmapTextureAtlas(null, 2*CAMERA_WIDTH, 2*CAMERA_HEIGHT, TextureOptions.默认); menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.menuBackgroundTexture, this, "land.png", 0, 0); SpriteBackground bg = new SpriteBackground(new Sprite(0, 0, menuBgTexture,this.getVertexBufferObjectManager())); mScene.setBackground(bg);....谁能帮帮我?

标签: android background andengine scene


【解决方案1】:

对于 VBOManager 对象,使用

this.getVertexBufferObjectManager();

【讨论】:

  • 谢谢!工作正常 :) bg 图像没有填满屏幕上的所有空间,我必须添加什么?
  • 你是如何初始化引擎的?什么大小,什么ResolutionPolicy
  • 好吧,我现在开始使用引擎,所以我还不太了解,但我的“onCreateEngine”是:camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT) ; EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), camera);私人最终 int CAMERA_WIDTH = 720;私人最终 int CAMERA_HEIGHT = 480;我的图像尺寸是 320x480
  • 我猜它填充了 480 并将 320 居中在 720 中,但是你想要发生什么?你的背景可以重复吗?
  • 是的,我将相机设置为相同的尺寸,一切都很好,再次感谢
【解决方案2】:

我的游戏也有同样的问题。解决方案是使用与相机尺寸相同的背景图像。例如,如果您的相机是 800X480,则图像也应具有相同的尺寸。此外,使 BitmapTextureAtlas 因子的尺寸为 2。在您的情况下,它应该是 512 像素 x 512 像素。希望对您有所帮助。

干杯!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    相关资源
    最近更新 更多