如何使视差背景适合屏幕

时间:2014-04-25 20:34:44

标签: android andengine

我正在用andengine开发一款安卓游戏。我使用AutoParallaxBackground重复背景。但我的背景图片不适合屏幕。如何解决相同的问题

这是我的代码

AutoParallaxBackground autoParallaxBackground=new AutoParallaxBackground(0, 0, 0, 10);
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-25.0f, new Sprite(0, 0, backgroundTextureRegion , engine.getVertexBufferObjectManager()))); 
    gameScene.this.setBackground(autoParallaxBackground);

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以尝试在创建Parallax Entity之前缩放精灵以适应屏幕,如下所示:

AutoParallaxBackground autoParallaxBackground=new AutoParallaxBackground(0, 0, 0, 10);

Sprite mySprite = new Sprite(0, 0, backgroundTextureRegion , engine.getVertexBufferObjectManager());
mySprite.setScaleY(1.0f/( mySprite.getHeight() / CAMERA_HEIGHT));
mySprite.setScaleX(1.0f/( mySprite.getWidth() / CAMERA_WIDTH));

autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-25.0f, mySprite)); 
gameScene.this.setBackground(autoParallaxBackground);