2012-08-10 34 views
2

我已經搜索了所有的論壇,但我無法獲得任何工作代碼。 我想從SD卡和引擎中加載一個圖像作爲精靈。 任何人都可以爲我提供代碼嗎?我使用在Andengine中加載圖片爲Sprite

File imageFile = new File("/path/to/image"); 
    BitmapTextureAtlas texture = new BitmapTextureAtlas(width , height , TextureOptions.DEFAULT); 
    ITextureSource fileTextureSource = new FileTextureSource(imageFile); 
    TextureRegion textureRegion = TextureRegionFactory.createFromSource(texture,fileTextureSource ,0,0); 

ITextureSource fileTextureSource = new FileTextureSource(imageFile); 

是給我的錯誤ITextureSource不能被解析爲一個類型。 我正在使用AndEngine GLES1。請幫助我,並給我一個方法來從SD卡製作精靈。

回答

6

我還沒有試過代碼,但我把它放在Eclipse中,並試圖修復它,以便它編譯。這是結果:

File imageFile = new File("/path/to/image"); 
BitmapTextureAtlas texture = new BitmapTextureAtlas(width , height , TextureOptions.DEFAULT); 
FileBitmapTextureAtlasSource fileTextureSource = new FileBitmapTextureAtlasSource(imageFile); 
TextureRegion textureRegion = TextureRegionFactory.createFromSource(texture,fileTextureSource ,0,0, true); 
+0

感謝它的工作。 :)我們只是錯過了加載紋理:) – 2012-08-13 10:12:56

+0

你好JohnEye和Jawad Amjad:我也有同樣的問題。尚未解決。 http://stackoverflow.com/questions/25501897/setting-screen-sprite-from-gallery-image-path-in-andengine請看看這個。 – user2085965 2014-08-26 09:05:08