2015-10-30 86 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()); 
相关问题