Advertisement
fishfpg

AndEngine Texture Source that takes a Bitmap

Sep 30th, 2011
1,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. // Texture Source that takes a Bitmap
  2. public class BitmapTextureAtlasSource extends BaseTextureAtlasSource implements IBitmapTextureAtlasSource
  3. {
  4.     private Bitmap mBitmap;
  5.  
  6.     public BitmapTextureAtlasSource(Bitmap pBitmap) {
  7.         super(0,0);
  8.         this.mBitmap = pBitmap.copy(Bitmap.Config.ARGB_8888, false);
  9.     }
  10.  
  11.     @Override
  12.     public int getWidth() {
  13.         return mBitmap.getWidth();
  14.     }
  15.  
  16.     @Override
  17.     public int getHeight() {
  18.         return mBitmap.getHeight();
  19.     }
  20.  
  21.     @Override
  22.     public BitmapTextureAtlasSource clone() {
  23.         return new BitmapTextureAtlasSource(Bitmap.createBitmap(mBitmap));
  24.     }
  25.  
  26.     @Override
  27.     public Bitmap onLoadBitmap(Config pBitmapConfig)
  28.     {
  29.         return mBitmap;
  30.     }
  31. }
  32.  
  33. // Usage:
  34. BitmapTextureAtlasSource source = new BitmapTextureAtlasSource(pBitmap);
  35. BitmapTextureAtlas texture = new BitmapTextureAtlas(mTextureSizeX, mTextureSizeY);
  36. texture.addTextureAtlasSource(source, 0, 0);
  37. mEngine.getTextureManager().loadTexture(texture);
  38. TextureRegion region = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement