2015-10-30 88 views
2

我對Android遊戲開發非常陌生,而且我正面臨有關屏幕圖像背景的問題。AndEngine完整圖像背景(寬度和高度)

這是我的一個擴展滿級代碼SimpleBaseGameActivity
修訂版攝像頭的寬度和高度對應於圖像尺寸

private final int CAMERA_WIDTH = 480;//800; 
private final int CAMERA_HEIGHT = 836; //1280; 

private Camera mCamera; 

//Background variables 
private TextureRegion region; 

private Scene mScene; 

@Override 
public EngineOptions onCreateEngineOptions() { 
    this.mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT); 

    return new EngineOptions(true, ScreenOrientation.PORTRAIT_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera); 
} 

@Override 
protected void onCreateResources() throws IOException { 
    BitmapTextureAtlas atlas = new BitmapTextureAtlas(this.getTextureManager(),CAMERA_WIDTH+CAMERA_WIDTH,CAMERA_HEIGHT+CAMERA_HEIGHT); 

    this.region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas,this,"snow_bg.png",0,0); 
    atlas.load(); 

} 

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

    this.mScene = new Scene(); 
    Sprite sprite = new Sprite(0,0,region,this.getVertexBufferObjectManager()); 
    this.mScene.setBackground(new SpriteBackground(sprite)); 

    return this.mScene; 
} 

,我現在面臨的問題是,背景圖片,這是不全面屏幕。我一直在尋找如何在AndEngine中拉伸圖像背景,但我還沒有找到任何好的資源。

這是屏幕截圖。

enter image description here

但圖像全屏視圖

enter image description here

請給我一些建議我應該怎樣做或示例代碼來實現我的目標。

在此先感謝。

回答

1

感謝盧卡斯Motyczka我能夠讓我的精靈,使其

float centerX = CAMERA_WIDTH/2; 
float centerY = CAMERA_HEIGHT/2; 

Sprite sprite = new Sprite(centerX,centerY,this.region, this.getVertexBufferObjectManager()); 


這裏是我完整的代碼

private final int CAMERA_WIDTH = 480; 
private final int CAMERA_HEIGHT = 836; 

private Camera mCamera; 
private TextureRegion region; 

private Scene mScene; 

@Override 
public EngineOptions onCreateEngineOptions() { 
    this.mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT); 

    return new EngineOptions(true, ScreenOrientation.PORTRAIT_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera); 
} 

@Override 
protected void onCreateResources() throws IOException { 
    BitmapTextureAtlas atlas = new BitmapTextureAtlas(this.getTextureManager(),CAMERA_WIDTH,CAMERA_HEIGHT); 
    this.region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas,this,"snow_bg.png",0,0); 
    atlas.load(); 

} 

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

    this.mScene = new Scene(); 
    float centerX = CAMERA_WIDTH/2; 
    float centerY = CAMERA_HEIGHT/2; 

    Sprite sprite = new Sprite(centerX,centerY,this.region, this.getVertexBufferObjectManager()); 
    this.mScene.setBackground(new SpriteBackground(sprite)); 

    return this.mScene; 
} 
2

首先:可愛的背景!第二:您的地區尺寸應該是2的權力(256x256,1024x512,2048x2048等等)。第三:你的圖像尺寸是什麼?它們與相機的寬度或高度相同嗎?如果不是你可以這樣做:

mScene.setBackground(new SpriteBackground(this.mCamera, new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, this.region))); . 

一般的想法是設置背景的尺寸太大,不僅是它的位置,因爲它不會自動拉伸到屏幕的大小。

+0

感謝您的想法先生,加上1給你.. –

0

更改此

Sprite sprite = new Sprite(0,0,region,this.getVertexBufferObjectManager()); 

Sprite sprite = new Sprite(0, 0, region,getWidth(), region.getHeight(), region, this.getVertexBufferObjectManager()); 
相關問題