編譯了新版的lib,發現RepeatingSpriteBackground構造函數是
[java]
public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
this(pCameraWidth, pCameraHeight, pTextureRegion, SCALE_DEFAULT, pVertexBufferObjectManager);
}
與網上的例子
[java]
this.background = new RepeatingSpriteBackground(CAMERA_WIDTH, CAMERA_HEIGHT,
getTextureManager(), AssetBitmapTextureAtlasSource.create(
this.getAssets(), "background.png"),
getVertexBufferObjectManager());
不負荷。於是琢磨這看了看源碼,經過試驗,可以通過
[java]
private TextureRegion getBackGround(){
//create by danielinbiti
AssetBitmapTexture mBitmapTexture = null;
try {
mBitmapTexture = new AssetBitmapTexture(mEngine.getTextureManager(), this.getAssets(), "background.png", BitmapTextureFormat.RGB_565,TextureOptions.REPEATING_BILINEAR);
} catch (IOException e) {
e.printStackTrace();
}
mBitmapTexture.load();
TextureRegion mRepeatingTextureRegion = TextureRegionFactory.extractFromTexture(mBitmapTexture);
return mRepeatingTextureRegion;
}
@Override
public void onCreateResources(OnCreateResourcesCallback arg0)
throws IOException {
// TODO Auto-generated method stub
BitmapTextureAtlas mTexture = new BitmapTextureAtlas(getTextureManager(),64,32,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mTexture, this, "face_circle_tiled.png", 0, 0,2,1);
this.background = new RepeatingSpriteBackground(CAMERA_WIDTH*1f, CAMERA_HEIGHT*1f,
this.getBackGround(),
getVertexBufferObjectManager());
/**
* 參數說明:
* mTexure是在內存中放置貼圖資源用的,64,32是圖片要求的寬和高,必須是2的n次方大小.如:2,4,8,16,32,64,128,512,1024....
* 並且要比原圖的寬高要大
*
* mFaceTextureRegion相當於從mTexure中扣圖,因為mTexure是由很多圖集組成的,要從中截取一片出來
* 0,0代表截圖的top,right坐標(起點坐標),2和1分別代表貼圖中一張存在2列1行
*
*/
mTexture.load();
arg0.onCreateResourcesFinished();
}