android游戏引擎andengine学习系列七:纹理贴图的理解

本文介绍了一种在游戏开发中加载和管理纹理资源的方法。通过使用BitmapTextureAtlas,可以有效地组织多个不同尺寸的图片资源,并确保它们在内存中高效利用。文章详细说明了如何为不同图片分配空间,避免纹理之间的重叠,以及如何根据图片的实际布局来创建TextureRegion。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public void onLoadResources() { // 想象一下mBitmapTextureAtlas是一张大画布,我们在上边画画,画了四张图片,每张是一个TextureRegion // 由于四个图片的大小为: // snapdragon_tiled.png : 400 X 180 // bana_tiled.png : 132 X 70 // face_box_tiled.png : 64 X 32 // helicopter_tiled.png : 96 X 84 // 故总共为 (400 + 132 + 64 + 96) X (180,70, 32, 84中的较大者) = 692 X 180 // 因为长和宽必须为2的幂次,所以我们取1024 X 256 this.mBitmapTextureAtlas = new BitmapTextureAtlas(1024, 256, TextureOptions.BILINEAR); // 设置png的起始路径,我们把所有的图片都放到了assets/gfx下边 BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); // 分别取四个动画的区域 // 解释一下创建mSnapdragonTextureRegion时的参数0,0,4,3, // 其中的0,0代表该区域在mBitmapTextureAtlas中的起始位置 // 我们需要设置该位置,使四个TextureRegion不重叠 // 同样,想象一下mBitmapTextureAtlas是一张大画布,我们在上边画画,画了四张图片,每张是一个TextureRegion // 下边解释4,3 // 4代表列数,3代表行数 // 观察一下图片就可以看见,snapdragon_tiled.png这幅图片是分了3行4列的 this.mSnapdragonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset( this.mBitmapTextureAtlas, this, "snapdragon_tiled.png", 0, 0, 4, 3); this.mHelicopterTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset( this.mBitmapTextureAtlas, this, "helicopter_tiled.png", 400, 0, 2, 2); this.mBananaTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset( this.mBitmapTextureAtlas, this, "banana_tiled.png", 496, 0, 4, 2); this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset( this.mBitmapTextureAtlas, this, "face_box_tiled.png", 628, 0, 2, 1); this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas); }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值