2012-06-07 191 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像素。希望有所幫助。

乾杯!