AndEngine Texture from Drawable

前端 未结 1 1208
深忆病人
深忆病人 2021-01-03 15:44

I\'m new to AndEngine.

For some reason, I have to create a TextureRegion from a Drawable variable.

I don\'t know if it is possible,

but my code is n

1条回答
  •  迷失自我
    2021-01-03 16:21

    I know this is not the best way of solving this problem, but you can turn your Drawable to a Bitmap and then create a TextureRegion from the Bitmap. Here's the code for creating a TextureRegion from a Bitmap:

    public class BitmapTextureSource implements ITextureSource {
    
            private Bitmap mBitmap = null;
    
            public BitmapTextureSource(Bitmap bitmap) {
                this.mBitmap = bitmap;
            }
    
            @Override
            public int getWidth() {
                return mBitmap.getWidth();
            }
    
            @Override
            public int getHeight() {
                return mBitmap.getHeight();
            }
    
            @Override
            public Bitmap onLoadBitmap() {
                return mBitmap.copy(mBitmap.getConfig(), false);
            }
    
            @Override
            public BitmapTextureSource clone() {
                return new BitmapTextureSource(mBitmap);
            }
    
        }
    

    Here's a link to help you make a Bitmap from your Drawable.

    Hope you'll find a simpler way, but this should do the job as well. Good luck!

    0 讨论(0)
提交回复
热议问题