Wednesday, 16 January 2013

Double buffering


Double buffering

Double buffering is a traditional method to prevent flickering when
moving graphics are shown. This method was used to handle redrawing
of the Canvas object.
As in the previous examples, instead of drawing the game elements
to the Canvas object directly, we have a separate image object, buf,
to which all elements are drawn at first. Only when everything has been
drawn to the image buffer are the contents of the second buffer shown
on the canvas using canvas.blit(buf). This way the user does not
have to see every individual drawing operation, but only the final result
for each frame, which also reduces flickering on the screen.

Module random

Last but not least, many games need a random ingredient to stay
interesting. Python provides a standard module called random that
contains methods to generate random numbers. Here, the function
random.randint() is used to generate integer values between the
given minimum and maximum values. Another often used function,
random.random(), returns a floating point value between 0 and 1.0.

No comments:

Post a Comment