Game Development Reference
In-Depth Information
draw polygons instead of bitmaps. To illustrate this concept, consider the following code snippet to
draw the Android canvas:
class MyLayout extends Linearlayout {
// ...
protected void onDraw(Canvas canvas)
{
// draw a point
canvas.drawPoint(x, y, aPaint);
// Draw lines
canvas.drawLines(float[] points, aPaint);
}
}
The Canvas class holds many draw calls. To draw something, you need four basic components: a
bitmap to hold the pixels, a Canvas to host the draw calls, a drawing primitive (e.g., Rect , Path , Text , or
Bitmap ), and a Paint to describe the colors and styles for the drawing. The basic primitives that could
help when drawing polygons follow:
drawPoint(float x, float y, Paint paint) draws a single point given X and Y
coordinates and a paint style.
drawArc (RectF oval, float startAngle, float sweepAngle, boolean
useCenter, Paint paint) draws the specified arc, which will be scaled to fit inside
the specified rectangle. oval defines the bounds of the rectangle used to define the
shape and size of the arc. startAngle is the starting angle (in degrees) where the
arc begins. sweepAngle is the sweep angle (in degrees) measured clockwise.
useCenter , if true , includes the center of the oval in the arc and closes it if it is
being stroked drawing a wedge.
drawCircle (float cx, float cy, float radius, Paint paint) draws a circle
using the specified paint. cx and cy define the X and Y coordinates of the center.
The circle will be filled or framed based on the Style in the paint.
drawLine (float startX, float startY, float stopX, float stopY, Paint
paint) draws a line segment with the specified start and stop coordinates, using
the specified paint. The style paint is ignored because a line is always framed.
drawLines (float[] pts, int offset, int count, Paint paint) draws a series of
lines. Each line is taken from four consecutive values in the pts array. Thus to
draw one line, the array must contain at least four values. These are the X and Y
coordinates of each point: X0, Y0, X1, Y1,...,Xn,Yn .
drawRect (Rect r, Paint paint) draws the specified Rect using the specified
Paint . The rectangle will be filled or framed based on the style in the paint.
drawRoundRect (RectF rect, float rx, float ry, Paint paint) draws the
specified rounded rectangle using the specified paint. The rounded rectangle will
be filled or framed based on the style in the paint. rx and ry define the xy radius of
the oval used to round the corners.
Search WWH ::




Custom Search