2012-06-07 196 views
5

我想设置我的场景背景,但我不知道如何!我已经阅读了很多关于这方面的内容,但我无法做到这一点。我是从Andengine开始的,很难找到我的问题的确切信息,都是主观的。添加背景Andengine场景Android

好了,我已经实现在场景中的闪屏,同时负载的所有资源和场景。 (https://sites.google.com/site/matimdevelopment/splash-screen---easy-way)

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

声明纹理:

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

加载资源和加载场景(他们被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),好了,这是什么?

+0

您使用哪种GLES? GLES2?我在GLES2中有onCreateResources()。我不知道为什么Nicolas Gramlich决定重新命名这样的关键功能,以及为什么他创建了一个没有文档的引擎/库。任何人都可以提供帮助吗? – shailenTJ

+1

当谈到文档时,谁知道他在想什么,上帝禁止你在andengine论坛上对此进行任何说明,如果你被告知应该只读源代码并解决它,我的意思是这些很好,但在源代码中甚至没有任何评论。它是一个耻辱真的是一个很好的小开源引擎,只是我的两美分:D – Spider

+0

我也面临类似的问题...我无法设置我的背景...这里是代码..menuBackgroundTexture = new BitmapTextureAtlas null,2 * CAMERA_WIDTH,2 * CAMERA_HEIGHT,TextureOptions.DEFAULT); \t menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.menuBackgroundTexture,this,“land.png”,0,0); SpriteBackground bg = new SpriteBackground(new Sprite(0,0,menuBgTexture,this.getVertexBufferObjectManager()));}};}};}}}; \t \t mScene.setBackground(bg); ....任何人都可以帮助我吗? – Rahul

回答

2

为VBOManager对象,使用

this.getVertexBufferObjectManager(); 
+0

谢谢!工作正常:) BG图像不填充屏幕上的所有空间,我必须添加任何东西? – Genaut

+0

你如何初始化引擎?什么规模,什么ResolutionPolicy – jmroyalty

+0

好了,我现在首先是发动机,所以我不很了解它,但我的“onCreateEngine”是: 相机=新相机(0,0,CAMERA_WIDTH,CAMERA_HEIGHT); EngineOptions engineOptions = new EngineOptions(true,ScreenOrientation。LANDSCAPE_FIXED,新的FillResolutionPolicy(),相机); private final int CAMERA_WIDTH = 720; private final int CAMERA_HEIGHT = 480; 我的图像大小是320x480 – Genaut

1

我也有同样的问题与我的比赛。解决方案是有一个与相机尺寸相同的背景图像。例如,如果您的相机是800X480,则图像的尺寸也应该相同。此外,使BitmapTextureAtlas因子的维数为2。在你的情况下,它应该是512×512像素。希望有所帮助。

干杯!