Can someone give me an example of how a child class would access the canvas of the parent class to draw something, i.e a bitmap:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
Bitmap bitmap_explosion = BitmapFactory.decodeResource(context.getResources(),com.forwardapps.tanks.R.drawable.explosion, options);
context.drawBitmap(bitmap_explosion, x, y, null);
This is what I have in the child, in the parent I’ve got:
Explosion xplode = new Explosion(this._context, 50, 50);
I’ve been looking around for a few hours now, no luck.
You don’t draw Bitmaps randomly in code. You would need to submit your object to some type of rendering view. So for example you might have:
When you call add explosions, dont forget to call
postInvalidateto ask the view to redraw it’s self.But to answer your question most directly, you want your child class to implement
Drawableand then pass the canvas to the child classesonDraw()method from the parent classesonDrawmethod.