Coding the component Interfaces
Each component will implement an interface so that although they behave differently they can be used the same way as one another because of polymorphism.
GraphicsComponent
Add the GraphicsComponent
interface.
import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; interface GraphicsComponent { void initialize(Context c, ObjectSpec s, PointF screensize); void draw(Canvas canvas, Paint paint, Transform t); }
All graphics components will need to be initialized (bitmaps loaded and scaled) as well as get drawn each frame. The initialize
and draw
methods of the interface make sure this can happen. The different ways that it will happen is taken care of by the specific graphics-related component classes.
Notice the parameters for each of the methods. The initialize
method will get a Context
, the specific(derived...