1
我是AndEngine的新手。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
我想安排在網格中繪製按鈕...我完成第一部分..按鈕上顯示drawable ..但你有任何想法如何可以適應網格矩形...任何建議? – CoDe