我是 AndEngine 的新手。
出于某种原因,我必须从 Drawable 变量创建一个 TextureRegion。
不知道有没有可能
但我的代码不起作用......
public class DrawableTextureSource implements ITextureSource {
private final int mWidth;
private final int mHeight;
private final Drawable mDrawable;
private final Context mContext;
public DrawableTextureSource(Context context, Drawable D) {
mContext = context;
mDrawable = D;
mWidth = D.getIntrinsicWidth();
mHeight = D.getIntrinsicHeight();
} // end DrawableTextureSource()
public DrawableTextureSource(Context context, Drawable D, int W, int H) {
mContext = context;
mDrawable = D;
mWidth = W;
mHeight = H;
} // end DrawableTextureSource()
public int getWidth() {
return mWidth;
} // end getWidth()
public int getHeight() {
return mHeight;
} // end getHeight()
public Bitmap onLoadBitmap(Config pBitmapConfig) {
Bitmap bitmap = Bitmap.createBitmap(1024, 1024, pBitmapConfig);
mDrawable.draw(new Canvas(bitmap));
return bitmap;
} // end onLoadBitmap()
public DrawableTextureSource clone() {
return new DrawableTextureSource(mContext, mDrawable, mWidth, mHeight);
} // end clone()
} // end class