2011-12-15 49 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