2011-12-15 85 views
0

我正在使用andengine开发游戏。我使用了两个纹理区域的纹理使用andengine覆盖纹理图像

public Texture xImg; 

public TextureRegion xRegion,yRegion; 

this.xImg=new Texture(64, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 

this.xRegion= TextureRegionFactory.createFromAsset(this.xImg, this, "level.png", 0, 0); 

this.yRegion= TextureRegionFactory.createFromAsset(this.xImg, this, "life.png", 0, 0); 

我为xRegion和yRegion创建了一个两个精灵。但是,两个精灵图像被水平和生活图像覆盖。如何共享两个纹理区域

回答

1

一个纹理你还是使用textureRegion的构造

this.myBitmapTextureAtlas = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 

BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 

this.xRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "level.png", 0, 0); 
this.yRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "life.png", 50, 0); 

最后2个值在TextureAtlas您所在地区指定的位置。所以,你必须使用不同的x,y值

检查本作更多的例子andengine examples

+0

使用旧版本的引擎。未找到BitmapTextureAtlas。如果我更改了最新的jar,我需要在编码中更改很多行。任何其他解决方案 – JohnRaja 2011-12-15 10:31:50

0

为了弄清情况,在AndEngine使用的纹理就是,你用createFromAsset方法将小图片的巨幅照片。我相信它是这样工作的,因为一些低级别的OpenGL ES技巧可以提高性能。

如果将坐标设置错误,图片将在纹理中重叠,稍后再显示它们时,会看到稍后添加到图片中的图像的一部分,您之前添加到纹理中。

此外,在较新版本的AndEngine中,还有一个新的类BuildableTexture,它使用一些聪明的算法自动为您放置图片。 http://www.andengine.org/forums/tutorials/buildabletextures-t415.html