Game Development Reference
In-Depth Information
/**
* Draw Sprite using polygon points
*
* @param canvas
* @param paint
*/
void draw(Canvas canvas, Paint paint) {
float[] points = sprite.getPoints();
if (points != null) {
canvas.drawLines(points, paint);
}
}
}
PolygonSprite defines the following methods:
render(int width, int height) computes the shape of the sprite given the width
and height of the screen. It also translates the polygon to the proper screen
position and applies rotation. Note that this method has nothing to do with the
actual screen painting (so perhaps “render” was not the best name choice).
isColliding(PolygonSprite s) checks if the sprite is colliding with another by
checking if the vertices of the sprite are inside the other (see Figure 4-1).
advance(int width, int height) moves the sprite around based on the delta X
and Y values. It also updates the sprites rotation values. The width and height
arguments represent the size of the screen. Note that the sprite will be wrapped
around if it moves off the screen.
draw(Canvas canvas, Paint paint) does the actual drawing of the sprite in the
Android layout. Its arguments are a Canvas object where the points will be drawn
and a Paint object for style and color information.
Figure 4-1. Polygon sprites about to collide
Search WWH ::




Custom Search