i am trying to make some kind of reflex like game for android, which draws circles in random places and the user must tap those circles as fast as possible. i am trying to make and addcircle(int amount) method, but for that i would like to redraw the same class, as it is the idea that the circles expand and then contract. so something like canvas.draw(MyCircleClass) would work. is it possible to create such a class that can be drawn to a canvas?
Share
You can wrap a class that can be drawn to a
Canvas, likeRect,Bitmapetc. Then to draw it on aCanvasyou would callcanvas.drawRect(myRectWrapper.getRect()).The other way would be to wrap the
Canvasitself. Then you can pass anything you like to it as long as you provide a method to transform your class into something, theCanvascan draw. It would look likemyCanvasWrapper.draw(myClass). Inside thedraw(myClass), your canvas wrapper would callcanvas.drawX(transformToX(myClass))The bottom line is that at some point you will need to call a
drawX()method the originalCanvas, providing one of the types it can handle.