andengine load texture

来源:互联网 发布:小区信息发布查询软件 编辑:程序博客网 时间:2024/06/16 04:25

记录一下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);



0 0
原创粉丝点击