andengine load texture

记录一下texture的几种加载方式

1 BitmapTextureAtlas

BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
ITextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, this, "main_menu.jpg", 0, 0);
mBitmapTextureAtlas.load();
float srx = CAMERA_WIDTH/2 - textureRegion .getWidth()/2;
float sry = CAMERA_HEIGHT - textureRegion .getHeight();
Sprite first = new Sprite(srx, sry, textureRegion , this.mEngine.getVertexBufferObjectManager());
this.scene.attachChild(first);

最基本的, 这里就不解释了


2 BuildableBitmapTextureAtlas

BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
BuildableBitmapTextureAtlas mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(this.getTextureManager(), 1024, 512, TextureOptions.NEAREST);
ITextureRegion firstTexureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "load_logo.png");
ITextureRegion secondTexureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "load_flash.png");
ITextureRegion thirdTexureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "load_flash_c.png");
mBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0));
mBitmapTextureAtlas.load();


float srx = CAMERA_WIDTH/2 - firstTexureRegion.getWidth()/2;
float sry = CAMERA_HEIGHT/2 - firstTexureRegion.getHeight()/2;
Sprite first = new Sprite(srx, sry, firstTexureRegion, this.mEngine.getVertexBufferObjectManager());
this.scene.attachChild(first);

BuildableBitmapTextureAtlas  的意义在于,将多个图片加载在一texture中,而你不需要去安排每张图的位置

如果想用第一种方式将几张图片加载到同一个texture中,BitmapTextureAtlasTextureRegionFactory.createFromAsset的最后两个参数则需要你自己填写,这个需要按照加载的图片的大小你自己安排


内部

AssetBitmapTextureAtlasSource abtas = AssetBitmapTextureAtlasSource.create(this.getAssets(), "gfx/background_grass.png")
ITextureRegion tr = BitmapTextureAtlasTextureRegionFactory.createFromSource(pBitmapTextureAtlas, abtas , pTextureX, pTextureY);

srx = CAMERA_WIDTH - tr.getWidth();
sry = CAMERA_HEIGHT - tr.getHeight();
Sprite second = new Sprite(srx, sry, tr, this.mEngine.getVertexBufferObjectManager());
this.scene.attachChild(second);

4

将多个单张图加载到一个tiledtextureregion中

BitmapTextureAtlas  bitmapTextureAtlas = new BitmapTextureAtlas (this.getTextureManager(), 256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
ITextureRegion[] childTextureRegions = new TextureRegion[2];
childTextureRegions[0] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(bitmapTextureAtlas,
                this,
                "start_default.png",
                0, 0);
childTextureRegions[1] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(bitmapTextureAtlas,
                this,
                "start_default.png",
                65, 0);
TiledTextureRegion tiledTextureRegion = TiledTextureRegion.create(bitmapTextureAtlas
                , 0, 0
                , 250
                , 128
                , 1, 2);



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值