Game Development Reference
In-Depth Information
The pygame.draw.line() Function
33. # draw some blue lines onto the surface
34. pygame.draw.line(windowSurface, BLUE, (60, 60), (120,
60), 4)
35. pygame.draw.line(windowSurface, BLUE, (120, 60), (60,
120))
36. pygame.draw.line(windowSurface, BLUE, (60, 120), (120,
120), 4)
The pygame.draw.line() function will draw a line on the Surface object that
you provide. Notice that the last parameter (the width of the line) is optional. If you pass 4
for the width, the line will be four pixels thick. If you do not specify the width parameter,
it will take on the default value of 1 .
The pygame.draw.circle() Function
38. # draw a blue circle onto the surface
39. pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)
The pygame.draw.circle() function will draw a circle on the Surface object
you provide. The third parameter is for the X and Y coordinates of the center of the circle
as a tuple of two ints. The fourth parameter is an int for the radius (that is, size) of the
circle in pixels. A width of 0 means that the circle will be filled in.
The pygame.draw.ellipse() Function
41. # draw a red ellipse onto the surface
42. pygame.draw.ellipse(windowSurface, RED, (300, 250, 40,
80), 1)
The pygame.draw.ellipse() function will draw an ellipse. It is similar to the
pygame.draw.circle() function, except that instead of specifying the center of the
circle, a tuple of four ints is passed for the left, top, width, and height of the ellipse.
The pygame.draw.rect() Function
44. # draw the text's background rectangle onto the surface
45. pygame.draw.rect(windowSurface, RED, (textRect.left - 20,
textRect.top - 20, textRect.width + 40, textRect.height +
Search WWH ::




Custom Search