0
最近我開始研究AndEngine。和引擎背景圖片
我想設置我的場景的背景圖像。
但由於某些原因,背景圖像沒有完全填滿屏幕。
任何建議和幫助?
這裏是我的源代碼:
public class MainActivity extends BaseGameActivity {
Scene sc;
protected final static int cam_wid = 320;
protected final static int cam_heigh = 456;
BitmapTextureAtlas texAtlas;
ITextureRegion texRegion;
@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
Camera ca = new Camera(0, 0, cam_wid, cam_heigh);
EngineOptions en = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
cam_wid, cam_heigh), ca);
return en;
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
// TODO Auto-generated method stub
load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
private void load() {
// TODO Auto-generated method stub
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
texAtlas = new BitmapTextureAtlas(getTextureManager(), 256, 512);
texRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
texAtlas, this, "imagery.png", 0, 0);
texAtlas.load();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// TODO Auto-generated method stub
this.sc = new Scene();
Sprite s = new Sprite(0, 0, cam_wid, cam_heigh, texRegion,
this.mEngine.getVertexBufferObjectManager());
SpriteBackground sb = new SpriteBackground(s);
sc.setBackground(sb);
pOnCreateSceneCallback.onCreateSceneFinished(sc);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}
我仍然無法找出問題所在。我嘗試根據手機的寬度和高度調整圖像的寬度和高度。 – user3624963
請更新以上代碼@ user3624963 –
更新我的代碼 – user3624963