Game Development Reference
In-Depth Information
17 - Graphics and Animation
stored in windowSurface with the color white. The fill() function will completely
cover the entire surface with the color we pass as the parameter. (In this case, we pass
BLACK to make the background black.)
An important thing to know about Pygame is that the window on the screen will not
change when we call the fill() method or any of the other drawing functions. These will
draw on the Surface object, but the Surface object will not be drawn on the user's
screen until the pygame.display.update() function is called. This is because
drawing on the Surface object (which is stored in the computer's memory) is much faster
than drawing to the computer screen. It is much more efficient to draw onto the screen once
and only after all of our drawing functions to draw to the surface.
The pygame.draw.polygon() Function
30. # draw a green polygon onto the surface
31. pygame.draw.polygon(windowSurface, GREEN, ((146, 0),
(291, 106), (236, 277), (56, 277), (0, 106)))
A polygon is any multisided shape with sides that are only straight lines. The
pygame.draw.polygon() function can draw any shape that you give it and fill the
inside space of the polygon. The tuple of tuples you pass it represents the XY coordinates
of the points to draw in order. The last tuple will automatically connect to the first tuple to
complete the shape.
Figure 17-5: Examples of Polygons.
Polygons only have straight lines for sides (circles and ellipses are not polygons). Figure
17-5 has some examples of polygons.
Search WWH ::




Custom Search